question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gradle: Fail Build if not formatted (with compileJava.dependsOn('spotlessApply'))

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nedtwiggcommented, Sep 24, 2019

Fixed in 3.24.3. Thanks for the testcase!

0reactions
nedtwiggcommented, Sep 18, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found