Declare formatter version to avoid spotless choosing a version#1151
Conversation
diffplug/spotless#2503 (comment) indicates that spotless chooses a formatter version based on the JDK running the formatting process. The spotless maintainer recommends that we declare a formatter version explicitly so that the formatter won't change based on the JDK version. Testing done: MAVEN_OPTS=-Djansi.force=true mvn -B -Dstyle.color=always -ntp clean verify In the winstone repository (where we saw the issue): Reverted the change that made the formatting independent of Java version in b95111923002d82598d4d85f67f40fa6170dda5e and then added explicit spotless version definition to the pom file so that I could confirm that changing Java versions does not change the formatting. MarkEWaite/winstone@78ea965 has the details . ~/bin/use_java17 mvn spotless:apply git status . ~/bin/use_java21 mvn spotless:apply git status
diffplug/spotless#2503 (comment) indicates that spotless chooses a formatter version based on the JDK running the formatting process. The spotless maintainer recommends that we declare a formatter version explicitly so that the formatter won't change based on the JDK version. Testing done: In this repository: mvn clean install versions:display-plugin-updates In the winstone repository (where we saw the issue): Reverted the change that made the formatting independent of Java version in b95111923002d82598d4d85f67f40fa6170dda5e and then added explicit spotless version definition to the pom file so that I could confirm that changing Java versions does not change the formatting. MarkEWaite/winstone@78ea965 has the details . ~/bin/use_java17 mvn spotless:apply git status . ~/bin/use_java21 mvn spotless:apply git status Matching pull request in plugin pom: * jenkinsci/plugin-pom#1151
| <palantirJavaFormat /> | ||
| <palantirJavaFormat> | ||
| <!-- Declare version so that spotless does not choose a version based on JDK version --> | ||
| <!-- https://github.com/diffplug/spotless/issues/2503#issuecomment-2953146277 --> |
There was a problem hiding this comment.
| <palantirJavaFormat> | ||
| <!-- Declare version so that spotless does not choose a version based on JDK version --> | ||
| <!-- https://github.com/diffplug/spotless/issues/2503#issuecomment-2953146277 --> | ||
| <version>2.67.0</version> |
There was a problem hiding this comment.
Where is this version number coming from? It does not seem to match https://github.com/diffplug/spotless/blob/2d32ccd3ef17e80f456f7bd3587846f2734bca71/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java#L32 (diffplug/spotless#2447 picking up palantir/palantir-java-format#1211).
There was a problem hiding this comment.
I suppose the point is merely that this is some arbitrary recent version, rather than picking one of two distinct much older versions depending on the JRE.
There was a problem hiding this comment.
It was the most recent release of palantir-java-format as of the day that I created this pull request, as reported by https://mvnrepository.com/artifact/com.palantir.javaformat/palantir-java-format . Sadly, a newer release arrived the day after this commit was created and then another release happened several weeks after that.
There was a problem hiding this comment.
Not a problem I think, just confirming.
diffplug/spotless#2503 (comment) indicates that spotless chooses a formatter version based on the JDK running the formatting process. The spotless maintainer recommends that we declare a formatter version explicitly so that the formatter won't change based on the JDK version. Testing done: In this repository: mvn clean install versions:display-plugin-updates In the winstone repository (where we saw the issue): Reverted the change that made the formatting independent of Java version in b95111923002d82598d4d85f67f40fa6170dda5e and then added explicit spotless version definition to the pom file so that I could confirm that changing Java versions does not change the formatting. MarkEWaite/winstone@78ea965 has the details . ~/bin/use_java17 mvn spotless:apply git status . ~/bin/use_java21 mvn spotless:apply git status Matching pull request in plugin pom: * jenkinsci/plugin-pom#1151
|
Caused #1162 |
|
Caused #1169 |
Declare formatter version to avoid spotless choosing a version
diffplug/spotless#2503 (comment) indicates that spotless chooses a formatter version based on the JDK running the formatting process. We intentionally run our tests with both JDK 17 and JDK 21. In some source code, that causes source code formatting to fail the build on one JDK version when it passes on the other JDK version.
Examples of the failure and workarounds that have been applied:
The spotless maintainer recommends that we declare a formatter version explicitly so that the formatter won't change based on the JDK version.
Matching pull request in Jenkins core pom:
Testing done
In the winstone repository (where we saw the issue):
Reverted the change that made the formatting independent of Java version in b95111923002d82598d4d85f67f40fa6170dda5e and then added explicit spotless version definition to the pom file so that I could confirm that changing Java versions does not change the formatting.
MarkEWaite/winstone@78ea965 has the details
The formatting was unchanged in both cases.
Submitter checklist