Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle plugin: removeFormat "java" is broken in 5.x #653

Closed
6 tasks done
jduan opened this issue Jul 28, 2020 · 4 comments
Closed
6 tasks done

Gradle plugin: removeFormat "java" is broken in 5.x #653

jduan opened this issue Jul 28, 2020 · 4 comments
Labels

Comments

@jduan
Copy link

jduan commented Jul 28, 2020

I have a Gradle multiple project setup and I'm trying to upgrade the spotless plugin (https://plugins.gradle.org/plugin/com.diffplug.gradle.spotless) from 3.24.2 to the latest version and I'm running into issues.

My setup looks like this:

  • In the root build.gradle file, we apply the spotless plugin and configure "spotless" for each subproject like this:
    spotless {
      ratchetFrom 'origin/main'
      enforceCheck = false
      java {
        target 'src/**/*.java'
        googleJavaFormat('1.4')
      }
      kotlin {
        target 'src/**/*.kt'
        ktlint('0.32.0')
      }
    }
  • Subprojects are owned by different teams and some of them want to configure spotless in their own projects' build.gradle file, eg:
spotless {
  removeFormat "java"
  java {
    target 'src/**/*.java'
    googleJavaFormat('1.7')
  }
}

This all works for version 3.24.2. However, it fails with the following error starting from version 3.25.0:

* What went wrong:
A problem occurred evaluating project ':projects:charisma'.
> Cannot add task 'spotlessJava' as a task with that name already exists.

This change looks suspicious: https://github.com/diffplug/spotless/blob/main/plugin-gradle/CHANGES.md#3250---2019-10-06 but I don't fully understand it.

Can someone take a look?

  • summary of problem
  • gradle or maven version: Gradle 6.2.1
  • spotless version: trying to upgrade to 3.24.2 to 5.1.0
  • operating system and version: macOS 10.15.6
  • copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible
  • copy-paste the full content of any console errors emitted by gradlew spotless[Apply/Check] --stacktrace

If you're just submitting a feature request or question, no need for the above.

@nedtwigg nedtwigg changed the title Can't configure spotless in subprojects Gradle plugin: removeFormat "java" is broken in 5.x Jul 28, 2020
@nedtwigg nedtwigg added the bug label Jul 28, 2020
@nedtwigg
Copy link
Member

Ah, yes. It looks like removeFormat is completely broken in our latest release. It's a bit tricky to restore it, but definitely possible.

Constructor<T> constructor = clazz.getConstructor(SpotlessExtension.class);
T formatExtension = constructor.newInstance(this);
formats.put(name, formatExtension);
createFormatTasks(name, formatExtension);
return formatExtension;

As a workaround, rather than calling removeFormat, you could use clearSteps() to achieve the same thing, e.g. in a subproject:

spotless {
  // removeFormat "java" (don't do this)
  java {
    clearSteps() // do this instead, same effect except it doesn't wipe out the target
    target 'src/**/*.java'
    googleJavaFormat('1.7')
  }
}

@jduan
Copy link
Author

jduan commented Jul 28, 2020

Hi @nedtwigg thanks for the quick response. I'll give that a try and report back.

@jduan
Copy link
Author

jduan commented Jul 29, 2020

@nedtwigg I confirmed that your suggestion worked! Thanks again for your prompt response!

@jduan jduan closed this as completed Jul 29, 2020
@nedtwigg
Copy link
Member

Thanks for the clean bug report! Is definitely a bug, and we should either fix it or remove the method in 6.x. Not high priority, but I'm gonna leave this open until we get around to one or the other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants