Repository navigation
Description
Why
The first version number is the Java version the formatter is built for, so 21.x does not load on JDK 17 to 20, and those JDKs are where much of the Maven world builds:
- apache/maven-parent's CI runs on JDK 17 only, and apache/maven tests on 17, 25 and 27.
- Format Java with open-java-format, which also runs on JDK 25 and later codehaus-plexus/plexus-pom#468 and Format Java with open-java-format, which also runs on JDK 25 and later mojohaus/mojo-parent#801 moved their Spotless step to open-java-format 21.0.2 and fall back to palantir-java-format on JDK 17 to 20. Format with palantir-java-format 2.103.0 on JDK 17 to match open-java-format codehaus-plexus/plexus-pom#469 then had to pick the palantir-java-format version whose output matches 21.0.2, 2.103.0, or the JDK 17 and JDK 21 legs disagree on the same file.
That match does not last: 21.1.0 already changed the output, and every later minor version will too. A 17 line with the same output gives such builds one formatter on every leg: 17.x on JDK 17 to 20, 21.x on 21 and later.
Proposal
A branch 17.X.X, cut from the 21.1.2 tag, where the formatter is built and tested on Java 17 only and released by tag, as 21.X.X is.
Versions. 17.<minor>.<build>, by the rules in Versions. The minor number follows the 21 line's: 17.1.x formats every file that javac 17 parses exactly as 21.1.x does, so the first release is 17.1.0. The build number counts the 17 line's own releases.
What the branch builds.
- Only the jars a build on the JVM loads:
open-java-formatandopen-java-format-spi. The Gradle plugin,open-java-format-jdk-bootstrap, the IntelliJ IDEA and Eclipse plugins, the native image, the WebAssembly module and the benchmarks stay on 21.X.X: the IDE plugins run in the IDE's JVM, and the native binary and the module do not depend on the user's JDK, so the 21 line's serve every user. - Temurin 17 everywhere:
mise.toml,JavaLanguageVersion.of(17)inopen-java-format.java-conventions.gradle, and aJDK17_HOMEingradle.propertiesin place ofJDK21_HOMEandGRAALVM_HOME. Gradle 9 itself runs on 17. - Compiling for 17 lists the code to rewrite: the record patterns in
switchoverBreakBehaviourinBreakBehaviour.javaanddoc/Level.java, and whatever else the compiler finds.Java21InputAstVisitorgoes, since it is built on javac 21's trees (PatternCaseLabelTree,DeconstructionPatternTree,ConstantCaseLabelTree,AnyPatternTree), and with it the tests behind@EnabledForJreRange(min = JAVA_21)and later. Formatteralready picksJava14InputAstVisitorbelow JDK 21 (Formatter.java#L143-L149). On JDK 21 and later the 21 line formatsswitchandcasethroughJava21InputAstVisitor, so the 17 line formats them through other code. The corpus check under "Done when" is what shows that the output is the same.
CI. ci.yml already runs on every *.X.X push. On 17.X.X:
buildon JDK 17, the one required check;- no
jdkmatrix (25, 26, 27, 28-ea), nonativeand nowasm: the line runs on JDK 17 to 20 and builds no image; - the ruleset "Default branch" covers 21.X.X only, so
17.X.Xgets the same rules: pull requests, signed commits,build, no force push, no deletion; - Dependabot and
update-pr-branch.ymlstay on 21.X.X. A dependency update the 17 line needs comes over as a backport.
Release by tag. release.yml runs on every tag, from the tagged commit, so a 17.* tag runs the branch's own copy. It keeps the release notes check, signing, the jars deployment and the publish job, and the draft GitHub release with the notes and the runnable -all.jar. It drops the native images and their deployment, the .deb packages, the WebAssembly module, the Gradle Plugin Portal and the JetBrains Marketplace. In open-java-format.release-conventions.gradle, branch = '21.X.X' becomes 17.X.X.
The GitHub release is not marked Latest (JReleaser's makeLatest), so releases/latest keeps pointing at the 21 line. The Homebrew tap, the Scoop bucket and the apt repository already move only to a higher version (follow-releases.yml), so a 17.x release leaves them alone.
Backports. A change on 21.X.X that changes the output, or fixes a crash or a security issue, gets a backport pull request to 17.X.X (git cherry-pick -x), labelled backport 17.X.X. A 17 minor version is released once every output change of the 21 minor version it follows is in. New syntax that javac 17 cannot parse, the IDE and Gradle plugins, the native image and the packages stay on 21.X.X.
Docs. On the branch, the README and CLAUDE.md say what the line is for and that it builds on Temurin 17. On 21.X.X, Versions names the 17 line. On openjavaformat.dev, the Spotless page shows a JDK 17 profile with 17.x in place of the palantir-java-format fallback, and how to keep Dependabot from offering 21.x to it.
To decide
- The Gradle plugin. Gradle 9 runs on Java 17, and a Gradle daemon on 17 cannot load the 21 line's plugin. Left out until someone asks?
- How long the line lives. For example until apache/maven-parent moves its JDK floor to 21, with the last release announced in the README.
- fmt-maven-plugin. It is built for Java 21 too (
java.version21 in its POM). A 17 line there belongs in that repository; Spotless withgroupArtifactworks with the 17 line as it is.
Alternatives looked at
- Keep falling back to palantir-java-format on JDK 17 to 20. What the Plexus and MojoHaus parents do today. The two legs agree only until the next minor version of the 21 line.
- Check the format only on JDK 21 and later. No work, but apache/maven-parent has a JDK 17 leg only, so it would check nothing.
- Run the 21 line from a JDK 17 build in another process. Spotless runs its
palantirJavaFormatstep inside the build's JVM. ItsnativeCmdstep can call the native binary, but then every machine that builds needs the binary installed.
Done when
17.X.Xexists with the rules of 21.X.X, and itsbuildruns on JDK 17 only;- a
17.1.0tag publishesdev.openjavaformat:open-java-formatandopen-java-format-spi17.1.0 to Maven Central and a draft GitHub release with the runnable jar, nothing else, and Latest stays on the 21 line; - 17.1.0 on JDK 17 and 21.1.2 on JDK 21 give the same output on the JDK 17
src.zipand the Gradle sources jars; - Spotless 3.12.0 with
groupArtifactdev.openjavaformat:open-java-formatand version 17.1.0 passesspotless:checkon JDK 17 on a project that 21.1.2 formatted; - the README and the Spotless page on openjavaformat.dev describe the line.
Activity