spotless icon indicating copy to clipboard operation
spotless copied to clipboard

Bind to maven phase is not working

Open thahgr opened this issue 1 year ago • 2 comments

If you are submitting a bug, please include the following:

Summary: Applying the spotless maven plugin to specific phases is not working. For example, having binded check to validate phase and apply to verify, running verify also applies spotless. Plugin goals run correctly individually eg mvn spotless:check

public git repo with example: https://gitlab.com/thahgr/spotless-maven-phases-test

to reproduce

  • modify a file adding an incorrect identation (eg new line)
  • run mvn verify

expected: the command should fail because spotless check failed actual: the command succeeds while writing files with spotless::apply

versions: maven: 3.8.1 java: 17 spotless: 2.43.0 google-java-plugin: 1.22.0 os: Ubuntu 22.04.4 LTS

Spotless configuration

<configuration>
    <java>
        <importOrder/>
        <removeUnusedImports/>
        <googleJavaFormat>
            <version>${google.java.format.version}</version>
            <style>GOOGLE</style>
            <reflowLongStrings>true</reflowLongStrings>
        </googleJavaFormat>
    </java>
    <lineEndings>UNIX</lineEndings>
</configuration>
<executions>
    <execution>
        <id>spotless-check</id>
        <goals>
            <goal>check</goal>
        </goals>
        <phase>verify</phase>
    </execution>
    <execution>
        <id>spotless-apply</id>
        <goals>
            <goal>apply</goal>
        </goals>
        <phase>validate</phase>
    </execution>
</executions>

thahgr avatar May 14 '24 08:05 thahgr

Any updates on this? I have exactly this problem. mvn spotless:check throws an error, however it doesn't in mvn verify with following config:

<executions>
    <execution>
        <id>spotless-check</id>
        <phase>verify</phase>
        <goals>
            <goal>check</goal>
        </goals>
    </execution>
</executions>

codeofandrin avatar Nov 09 '25 22:11 codeofandrin

Summary: Applying the spotless maven plugin to specific phases is not working.

It is working fine.

For example, having binded check to validate phase and apply to verify, running verify also applies spotless.

👀 What else is expected?

public git repo with example: https://gitlab.com/thahgr/spotless-maven-phases-test

to reproduce

* modify a file adding an incorrect identation (eg new line)

* run mvn verify

expected: the command should fail because spotless check failed actual: the command succeeds while writing files with spotless::apply

In maven's default lifecycle validate phase comes before verify, so with the configuration as in reproducer - :apply is applied first and only then :check is checking at the end. And later phase includes all previous phases.

IMO - this deserves invalid label and to be closed as not planned.

pzygielo avatar Nov 10 '25 08:11 pzygielo