Closed5
spotlessが動かない
spotless-maven-plugin
を使って mvn spotless:apply
しても動かない.
spotless-maven-plugin: 2.43.0
pom.xml
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<configuration>
<formats>
<format>
<includes>
<include>src/main/java/**/*.java</include>
<include>src/test/java/**/*.java</include>
</includes>
<trimTrailingWhitespace/>
<endWithNewline/>
<indent>
<spaces>true</spaces>
<spacesPerTab>4</spacesPerTab>
</indent>
</format>
</formats>
<java>
<googleJavaFormat>
<style>AOSP</style>
</googleJavaFormat>
</java>
</configuration>
</plugin>
</plugins>
</build>
target/spotless-index
を削除してもフォーマットされない.
[INFO] --- spotless:2.43.0:apply (default-cli) @ *** ---
[INFO] Index file does not exist. Fallback to an empty index
[INFO] Spotless.Java is keeping * files clean - 0 were changed to be clean, 0 were already clean, * were skipped because caching determined they were already clean
バージョン 2.35.0
未満( 2.34.0
以下)だと動く. 以下の変更が影響?
Enable incremental up-to-date checking by default. (#1621)
spotless/plugin-maven/CHANGES.md at main · diffplug/spotless
upToDateChecking
を false
にするとフォーマットされる.
pom.xml
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<configuration>
<upToDateChecking>
<enabled>false</enabled>
</upToDateChecking>
<formats>
<format>
<includes>
<include>src/main/java/**/*.java</include>
<include>src/test/java/**/*.java</include>
</includes>
<trimTrailingWhitespace/>
<endWithNewline/>
<indent>
<spaces>true</spaces>
<spacesPerTab>4</spacesPerTab>
</indent>
</format>
</formats>
<java>
<googleJavaFormat>
<style>AOSP</style>
</googleJavaFormat>
</java>
</configuration>
</plugin>
</plugins>
</build>
format
タグと他のタグ, 例えば java
などがあるとフォーマットが利かなくなるらしい.
This worked fine for pre-2.35 version, this also works fine if we disable up-to-date index:
<upToDateChecking> <enabled>false</enabled> </upToDateChecking>
試しに format
タグを消すと確かに動作した.
pom.xml
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<configuration>
<java>
<googleJavaFormat>
<style>AOSP</style>
</googleJavaFormat>
</java>
</configuration>
</plugin>
</plugins>
</build>
結論
spotless-maven-plugin:2.35.0
以降では format
タグは使わずに java
タグだけに書くのが正しい.
pom.xml
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<configuration>
<java>
<includes>
<include>src/main/java/**/*.java</include>
<include>src/test/java/**/*.java</include>
</includes>
<trimTrailingWhitespace/>
<endWithNewline/>
<indent>
<spaces>true</spaces>
<spacesPerTab>4</spacesPerTab>
</indent>
<googleJavaFormat>
<style>AOSP</style>
</googleJavaFormat>
</java>
</configuration>
</plugin>
</plugins>
</build>
このスクラップは2024/03/14にクローズされました