Gradle: Fail Build if not formatted (with compileJava.dependsOn('spotlessApply'))
See original GitHub issueI am using Gradle 5.2 with version 3.24.2
of the spotless plugin.
I want to format JSF XHTML files using the eclipse formatter, using the following config:
...
if (!isCI) {
project.afterEvaluate {
compileJava.dependsOn('spotlessApply')
}
}
...
spotless {
format 'xml', {
target '**/*.xhtml'
eclipseWtp('html')
indentWithSpaces(2)
endWithNewline()
trimTrailingWhitespace()
paddedCell()
encoding 'UTF-8'
}
}
The goal is to automatically format the source on every build, when not in the CI environment but fail, if in the CI environment and the source is not formatted.
Formatting on every build works due to the afterEvaluate
block, but when running ./gradlew check
or ./gradlew spotlessCheck
on unformatted sources, either in the CI environment or with the afterEvaluete
block commented out, the build does not fail.
What am I missing? I want check
and spotlessCheck
to fail, if the sources are not formatted…
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
java - Make gradle compileJava dependsOn spotlessApply
To solve this, simply depend on the task's name (i.e. as a string) instead and Gradle will resolve the task when its needed....
Read more >Use project.configure to implement custom plugin - Help/Discuss
Hi, I have created a custom plugin. The way I have programmed it, is not documented and I wanted to verify that this...
Read more >Improve code formatting on every commit - Medium
Run 'gradlew spotlessApply' to fix these violations. The command above is pretty self explanatory.
Read more >build.gradle · Hyperledger/besu - Gitee.com
An enterprise-grade Java-based, Apache 2.0 licensed Ethereum client https://wiki.hyperledger.org/display/besu.
Read more >diffplug/spotless - Gitter
Could not determine the dependencies of task ':integrity:spotlessApply'. ... dependsOn javaCompile, CI will pass even if people commit badly formatted code, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in
3.24.3
. Thanks for the testcase!Yep. Lots of formatters have non-idempotent corner-cases. Looks like your prod repo has one of them. That’s what paddedCell is for, but clearly something about it is broken. Your test repo is a perfect testcase for fixing it, and I’m happy to merge any PR’s, but I won’t get to investigating and implementing a fix myself until this weekend. I expect we should be able to ship a fix on Monday.