Skip to content

Declare formatter version to avoid spotless choosing a version#1151

Merged
MarkEWaite merged 1 commit intojenkinsci:masterfrom
MarkEWaite:declare-palantir-version-to-reduce-JDK-variation
Jun 26, 2025
Merged

Declare formatter version to avoid spotless choosing a version#1151
MarkEWaite merged 1 commit intojenkinsci:masterfrom
MarkEWaite:declare-palantir-version-to-reduce-JDK-variation

Conversation

@MarkEWaite
Copy link
Contributor

@MarkEWaite MarkEWaite commented Jun 8, 2025

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

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

The formatting was unchanged in both cases.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

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
@MarkEWaite MarkEWaite added the bug label Jun 8, 2025
MarkEWaite added a commit to MarkEWaite/pom that referenced this pull request Jun 8, 2025
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
@jglick jglick linked an issue Jun 24, 2025 that may be closed by this pull request
<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 -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem I think, just confirming.

MarkEWaite added a commit to jenkinsci/pom that referenced this pull request Jun 26, 2025
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
@MarkEWaite MarkEWaite merged commit 7e08339 into jenkinsci:master Jun 26, 2025
2 checks passed
@MarkEWaite MarkEWaite deleted the declare-palantir-version-to-reduce-JDK-variation branch June 26, 2025 18:24
@basil
Copy link
Member

basil commented Jul 2, 2025

Caused #1162

@basil
Copy link
Member

basil commented Jul 21, 2025

Caused #1169

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nondeterministic version of Palantir Java formatter used

4 participants