Skip to content

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

Closed
@vbrandl

Description

@vbrandl

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions