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.
- Gradle 9 runs on Java 17, but a Gradle daemon on 17 cannot load the 21 line's Gradle plugin at all.
- fmt-maven-plugin is built for Java 21 only because the formatter is: its POM says "open-java-format is compiled for Java 21, so the plugin cannot run on anything older".
The palantir-java-format 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 21.X.X once the formatter's cases are split by the JDK that parses them (below), where the formatter and the Gradle plugin are built for Java 17, tested on JDK 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. If #271, an output change, lands on 21.X.X before the branch is cut, the first release is 17.2.0, after 21.2.0.
What the branch builds.
- What a build on the JVM loads:
open-java-format,open-java-format-spi,open-java-format-jdk-bootstrapand the Gradle plugingradle-open-java-format, with all its plugin IDs. 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. On17.X.Xthey stay in the tree, left out ofsettings.gradle, so a backport that touches them applies as it is. - javac 21 compiles for Java 17, as palantir-java-format compiled for 11: the toolchain stays 21, every
JavaCompilegetssourceCompatibilityandtargetCompatibility17 and no--release(which javac refuses next to the--add-exportsofjdk.compiler). Every class comes out as class file 61,Java21InputAstVisitorincluded, and Gradle Module Metadata saysorg.gradle.jvm.version17. Error Prone 2.52.0, NullAway and Checkstyle stay as they are, on 21; Gradle itself has to stay on 21 anyway, since the root build applies the releasedgradle-open-java-format:21.0.2. The tests run on JDK 17.mise.tomlinstalls Temurin 21 and 17, andgradle.propertiesreadsJDK21_HOMEandJDK17_HOMEinstead ofJDK21_HOMEandGRAALVM_HOME. The Gradle plugin's TestKit tests build with Gradle 9.3.1 on the JDK 17 test JVM, so they show that the plugin loads in a Gradle on 17. - javac 21 at
-source 17still rejects Java 21 syntax, but takes Java 18+ APIs against its own class library. AcompileJava17Checktask incheckcompiles each module's main sources once more with javac 17, without thejava21package and without Error Prone, and fails on such an API; the test sources are covered by running on JDK 17. - A trial on a scratch copy found little to rewrite: the record patterns in
switchoverBreakBehaviourinBreakBehaviour.javaanddoc/Level.java, the type patterns inswitchin the Gradle plugin'sXmlUtils.java,ExecutorServiceas a try-with-resources resource inMain.java(AutoCloseablesince Java 19), andList.getFirst()/getLast()in the test helperCaseFile.java. With those rewritten, the jdk-bootstrap and Gradle plugin tests all pass on JDK 17, and so do the core's but one,straySemicolonBetweenImportsReportsTheParseError(javac 17 still accepts a;between imports). The 17 line reports that;itself, with javac 21's message and position (2:1: error: extraneous semicolon), so a file that 21.x rejects fails on 17.x too, and the test stays as it is. The test classes for JDK 21, 25 and 28 stay and skip themselves on 17. FormatterCasesJava21Testis enabled from JDK 21 only (ADR-002), so the trial above did not run the 918 case files oftest-cases-java21at all. Run on JDK 17, 891 of them give the 21 line's expected output throughJava14InputAstVisitor, and on JDK 21 the same 17-target classes pass all 918 throughJava21InputAstVisitor; the other 27 are 9 cases in three line endings whose syntax javac 17 does not parse (CompactSource,ojf-issue-24-jbang-compact-source,I1309,SwitchDouble,SwitchGuardClause,SwitchRecord,SwitchUnderscore,Unnamed,UnnamedPattern). Before17.X.Xis cut again, 21.X.X moves the cases javac 17 parses totest-cases-java17/, run by aFormatterCasesJava17Testwith no JRE condition (17 is JUnit 6's floor), and leaves the 9 intest-cases-java21/, with ADR-002 amended to match. The 17 line then runstest-cases-java17/on JDK 17, and a later case lands in the right folder on 21.X.X, so its backport applies as it is.Formatterpicks the visitor by the running JDK and loadsJava21InputAstVisitorby name on 21 and later (Formatter.java#L143-L149), and both lines keep that. On 21.X.X, with the case split,Java14InputAstVisitorbecomesJava17InputAstVisitor, the visitor for JDK 17 to 20, andFormatterchooses between it andJava21InputAstVisitoronly. The 17.x jar carries both: on JDK 17 it formats throughJava17InputAstVisitor, and on 21 and later, which the 17 line does not test, throughJava21InputAstVisitor, as 21.x does. The corpus check under "Done when" is what shows that the JDK 17 output is the same.- The Gradle plugin has no native formatter on this line:
NativeImageFormatProviderPluginresolvesopen-java-format-nativeat the plugin's own version, and the 17 line publishes none. Withopenjavaformat.native.formatter=truethe 17.x plugin fails with a message that says the native binary comes with the 21 line, rather than with a resolution error.
CI. ci.yml already runs on every *.X.X push. On 17.X.X:
buildon JDK 17, the Gradle plugin's tests included, as the one required check. Nothing tests the 17 line on JDK 21 or later: 21.x is the stable line there, and a build that moves to JDK 21 moves to it;- no
jdkmatrix (25, 26, 27, 28-ea), nonativeand nowasm: the line 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, the Gradle Plugin Portal, and the draft GitHub release with the notes, the runnable -all.jar and the Gradle plugin. It drops the native images and their deployment, the .deb packages, the WebAssembly module 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, the apt repository and fmt-maven-plugin's README bump already move only to a higher version (follow-releases.yml), so a 17.x release leaves them alone. After the first 17 release, check which version the Gradle Plugin Portal shows as the plugin's latest.
The Maven plugin. fmt-maven-plugin brings no formatter: the build names the open-java-format dependency, and the plugin formats with that version. Built for Java 17 instead of 21, the same plugin works with 17.x on JDK 17 and with 21.x on 21 and later, without a branch of its own. The change is ready in openjavaformat/fmt-maven-plugin, built and tested on Temurin 17 with 17.x, and waits for 17.1.0 on Maven Central.
Backports. A change on 21.X.X that changes the output, or fixes a crash or a security issue in the formatter or the Gradle plugin, 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 plugins, the native image and the packages stay on 21.X.X.
How long the line lives. As long as large projects build on JDK 17: apache/maven-parent, the Plexus and MojoHaus parents. The README announces its last release.
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 Gradle, Maven and Spotless pages show how a JDK 17 build uses 17.x, and the Spotless page drops the palantir-java-format fallback; each says how to keep Dependabot from offering 21.x to it.
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, and Gradle builds on 17 have no plugin at all.
- 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, and a Gradle plugin built for 21 cannot even be applied on 17. Spotless'snativeCmdstep can call the native binary, but then every machine that builds needs the binary installed.
Done when
- 21.X.X has
Java17InputAstVisitorand runs its cases fromtest-cases-java17/(on every JDK) andtest-cases-java21/, and17.X.Xis cut from it with the rules of 21.X.X, itsbuildon JDK 17 only; - every class of 17.1.0 is class file 61,
compileJava17Checkpasses, and on JDK 17 the cases oftest-cases-java17/pass and a;between imports fails withextraneous semicolon, as on 21.x; - a
17.1.0tag publishesopen-java-format,-spiand-jdk-bootstrap17.1.0 to Maven Central, the Gradle plugin to the Plugin Portal, and a draft GitHub release, 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; - on JDK 17,
dev.openjavaformat.java-format17.1.0 applies andformatDiffruns in a Gradle 9 build, and Spotless 3.12.0 withgroupArtifactdev.openjavaformat:open-java-formatand version 17.1.0 passesspotless:checkon a project that 21.1.2 formatted; - fmt-maven-plugin runs
checkon JDK 17 with open-java-format 17.1.0; - the README and the Gradle, Maven and Spotless pages on openjavaformat.dev describe the line.
Activity
[-]A 17.X.X release line: the formatter on Java 17, backported from 21.X.X[/-][+]A 17.X.X release line: the formatter and the Gradle plugin on Java 17, backported from 21.X.X[/+]