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

Regression between 2.34.0 and 2.35.0 #1653

Closed
3 tasks
stawirej opened this issue Apr 3, 2023 · 7 comments
Closed
3 tasks

Regression between 2.34.0 and 2.35.0 #1653

stawirej opened this issue Apr 3, 2023 · 7 comments

Comments

@stawirej
Copy link

stawirej commented Apr 3, 2023

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

After upgrading to 2.35.0 from 2.34.0 spotless-maven-plugin, spotless stopped to report format violation (always success on mvn spotless:check) and stopped reformatting code (always success on mvn spotless:apply).

Spotless used with google java format 1.16.0

  • gradle or maven version: Apache Maven 3.8.6
  • spotless version: 2.35.0
  • operating system and version: OS name: "mac os x", version: "13.3", arch: "aarch64", family: "mac"
@blacelle
Copy link
Contributor

blacelle commented Apr 5, 2023

@stawirej Can you provide a reproduction scenario ? Thanks

@stawirej
Copy link
Author

stawirej commented Apr 13, 2023

  • Please checkout project https://github.com/stawirej/timeflow
  • In pom change <spotless.version>2.34.0</spotless.version> to version 2.35.0 or 2.36.0 (issue in both versions)
  • Make mess in class pl/amazingcode/timeflow/Time.java
  • run mvn spotless:apply
  • It will print BUILD SUCCESS but Time.java file will not be formatted.

@lutovich
Copy link
Contributor

Hi @stawirej,

I think #1621 might be causing the problem. I followed the described steps but both mvn spotless:check and mvn spotless:apply worked as expected. The up-to-date index file in target/spotless-index might be incorrect.

Could you please paste the output of the following commands:

$ cat target/spotless-index
$ stat src/main/java/pl/amazingcode/timeflow/Time.java

File spotless-index stores last modified timestamp for every file that was processed by spotless. The timestamp in the index file should be the same as returned by the stat command.

To work around this problem it should be enough to run mvn clean which deletes the index file.

@stawirej
Copy link
Author

Hi @lutovich,

thank you for your feedback.

Neither mvn spotless:check or mvn spotless:apply produces target/spotless-index for https://github.com/stawirej/timeflow

cat target/spotless-index
cat: target/spotless-index: No such file or directory

I am facing reported issue not only on this project, but in multiple, production projects.

Please check some obfuscated logs from big production-level project:

stat ../SomeClass.java
16777229 21656051 -rw-r--r-- 1 user staff 0 7320 "Apr 14 11:14:56 2023" "Apr 14 11:14:54 2023" "Apr 14 11:14:54 2023" "Apr 14 11:13:11 2023" 4096 16 0 ..SomeClass.java

cat ./target/SomeClass.java
/SomeClass.java 2023-04-14T09:14:54.953613084Z

After mvn clean and mvn spotless:check or mvn spotless:apply

cat ./target/SomeClass.java
../SomeClass.java 2023-04-14T09:14:54.953613084Z

stat ../SomeClass.java
16777229 21656051 -rw-r--r-- 1 user staff 0 7320 "Apr 14 11:14:56 2023" "Apr 14 11:14:54 2023" "Apr 14 11:14:54 2023" "Apr 14 11:13:11 2023" 4096 16 0 ../SomeClass.java

Issue still present. spotless reported BUILD SUCCESS but code was not formatted.

@blacelle
Copy link
Contributor

blacelle commented Apr 14, 2023

@stawirej The fix is at the end
@nedtwigg this is a duplicate of #1656 (multiple configurations formats covering the same files). As this ticket is also quite recent, I suppose something changed recently, pushing to these new unexpected behavior (inconsistency in my case, SUCCESS but not formatted in this case)


Reproduction additional notes:

open src/main/java/pl/amazingcode/timeflow/Time.java
[INFO] ----------------------< pl.amazingcode:timeflow >-----------------------
[INFO] Building timeflow 1.5.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- spotless-maven-plugin:2.35.0:apply (default-cli) @ timeflow ---
[INFO] Index file does not exist. Fallback to an empty index
[INFO] Writing clean file: /Users/blacelle/workspace3/timeflow/src/main/java/pl/amazingcode/timeflow/Time.java
[INFO] Spotless.Java is keeping 4 files clean - 1 were changed to be clean, 3 were already clean, 0 were skipped because caching determined they were already clean
[INFO] Sorting file /var/folders/8b/p64c8tfs4d7gf3v8tcmwbz580000gn/T/pom9851023271199741303.xml
[INFO] Pom file is already sorted, exiting
[INFO] Spotless.Pom is keeping 1 files clean - 0 were changed to be clean, 1 were already clean, 0 were skipped because caching determined they were already clean
[INFO] Spotless.Format is keeping 4 files clean - 0 were changed to be clean, 0 were already clean, 4 were skipped because caching determined they were already clean
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.312 s
[INFO] Finished at: 2023-04-14T22:24:29+04:00
[INFO] ------------------------------------------------------------------------

Mmm. This makes me think of #1656 (do not ask me why).

Current (faulty) configuration:

    <plugin>
       <groupId>com.diffplug.spotless</groupId>
       <artifactId>spotless-maven-plugin</artifactId>
       <version>${spotless.version}</version>
       <configuration>
         <java>
           <toggleOffOn>
             <off>@formatter:off</off>
             <on>@formatter:on</on>
           </toggleOffOn>
           <googleJavaFormat>
             <version>1.16.0</version>
           </googleJavaFormat>
           <removeUnusedImports></removeUnusedImports>
         </java>
         <formats>
           <format>
             <includes>
               <include>src/main/java/**/*.java</include>
               <include>src/test/java/**/*.java</include>
             </includes>
             <indent>
               <spaces>true</spaces>
               <spacesPerTab>2</spacesPerTab>
             </indent>
           </format>
         </formats>
[...]
       </configuration>
[...]
     </plugin>

-> you **/*.java are indeed caught by 2 formats block, which is an invalid configuration (as per #1656). I can not guess right now why the behavior changed since 2.34.0


@stawirej This is fixed by a configuration like:

  <plugin>
    <groupId>com.diffplug.spotless</groupId>
    <artifactId>spotless-maven-plugin</artifactId>
    <version>${spotless.version}</version>
    <configuration>
      <java>
        <indent>
          <spaces>true</spaces>
          <spacesPerTab>2</spacesPerTab>
        </indent>
        <toggleOffOn>
          <off>@formatter:off</off>
          <on>@formatter:on</on>
        </toggleOffOn>
        <googleJavaFormat>
          <version>1.16.0</version>
        </googleJavaFormat>
        <removeUnusedImports></removeUnusedImports>
      </java>
      <pom>
        <includes>
          <include>pom.xml</include>
        </includes>
        <sortPom></sortPom>
      </pom>
    </configuration>
    <executions>
      <!-- Runs in compile phase to fail fast in case of formatting issues. -->
      <execution>
        <id>spotless-check</id>
        <goals>
          <goal>check</goal>
        </goals>
        <phase>compile</phase>
      </execution>
    </executions>
  </plugin>

@nedtwigg
Copy link
Member

nedtwigg commented Apr 14, 2023

why the behavior changed since 2.34.0

I think it is because up-to-date checking was enabled by default starting in 2.35.0

Seems that up-to-date checking makes it more important that the format targets are non-overlapping.

Closing as dupe of #1656.

@stawirej
Copy link
Author

Thank you for your support.

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

No branches or pull requests

4 participants