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 after #294 to #297 (at a884c7b), where the formatter and the Gradle plugin are built, tested and run on JDK 17 only, and released by tag, as 21.X.X is. The branch changes only what JDK 17 cannot build; everything else stays as on 21.X.X, so that backports apply as they are.
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. #271, an output change, is not on the branch: its backport makes 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, commented out insettings.gradle, so a backport that touches them applies as it is. - JDK 17 only: the Gradle daemon, the toolchain, the tests and CI run on Temurin 17.
mise.tomlinstalls Temurin 17, andgradle.propertiesreadsJDK17_HOMEinstead ofJDK21_HOMEandGRAALVM_HOME. javac 17 itself rejects the syntax and the APIs newer than Java 17, so there is no-source/-targettrick and no extra check task. A build plugin that does not load on Gradle with JDK 17 goes back to its last release that does. - Error Prone, error-prone-support, NullAway and Checkstyle are not part of the branch's build: their releases built for Java 21 do not load on JDK 17, and the code they would check is checked on 21.X.X and comes here only as backports. forbidden-apis stays, it runs on 17. The released
gradle-open-java-format:21.0.2that formats this repository does not load on Gradle with JDK 17 either, so the branch does not apply it until 17.1.0 is out and then applies 17.1.0; until then, changes made on the branch are formatted with the 21 line's-all.jar. - 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 and cases for JDK 21, 25 and 28 stay as they are and skip themselves on 17, which keeps backports free of conflicts. 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). Test the visitor for JDK 17 on every JDK, and make it the base visitor #294 moved the cases javac 17 parses totest-cases-java17/, run through the visitor of JDK 17 on every JDK by aFormatterCasesJava17Testwith no JRE condition (17 is JUnit 6's floor), and left the 9 intest-cases-java21/, with ADR-002 amended to match. Check the cases of Java 17 on every surface through the visitor for JDK 17 #296 runs them through every surface,formatSourceAndFixImports, the service,--output-replacementsand the command line's range output, as nothing else does on JDK 17. 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.- On 21.X.X,
Formatterpicks the visitor by the running JDK:JavaInputAstVisitor, into which Test the visitor for JDK 17 on every JDK, and make it the base visitor #294 mergedJava14InputAstVisitor, up to JDK 20, andJava21InputAstVisitor, loaded by name, from 21; Call the syntax tree APIs of JDK 17 directly #295 calls the tree APIs of JDK 17 directly. javac 17 cannot compileJava21InputAstVisitor, so17.X.Xdeletes it andFormattertakesJavaInputAstVisitoron every JDK. On JDK 21 and later, which the 17 line does not test, 17.x formats Java 17 syntax through it;FormatterCasesJava17Testchecks that very pairing in the 21 line's CI on JDK 21 to 28. Syntax newer than Java 17 needs 21.x. The corpus check under "Done when" is what shows that the JDK 17 output is the same. - The 17 line publishes no native image, and its Gradle plugin keeps the native formatter as it is. Let a build name the version of the native image #297 added
openjavaformat.native.formatter.version, the version ofopen-java-format-nativethe plugin runs, by default the plugin's own. A build on 17.x that wants the native formatter sets it to the 21 release of the same minor version, 21.1.2 for 17.1.0: the binary does not depend on the build's JDK and formats as 17.1.x does. Without it, 17.x asks foropen-java-format-native:17.x, which does not exist, and the build fails to resolve it. The docs say so.
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 the ruleset
17.X.Xgives the branch 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). 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, the Gradle page shows openjavaformat.native.formatter.version, 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 runs its cases from
test-cases-java17/(on every JDK and every surface) andtest-cases-java21/(done in Test the visitor for JDK 17 on every JDK, and make it the base visitor #294 and Check the cases of Java 17 on every surface through the visitor for JDK 17 #296), and17.X.Xis cut from it (done at a884c7b) with the rules of 21.X.X, itsbuildon JDK 17 only; ./gradlew checkpasses on JDK 17 alone, every class of 17.1.0 is class file 61, 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; withopenjavaformat.native.formatter.version=21.1.2, the 17.1.0 plugin formats with the 21.1.2 native image; - 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[/+]abashev commentedon Dec 1, 2026
17.1.0 is out.
17.X.Xbuilds, tests and runs on JDK 17 alone (Build, test and run the 17 line on JDK 17 #298) and releases by tag (Release the 17 line by tag, with notes for 17.1.0 and its README #299); a tag of another line is refused there and on 21.X.X (Refuse a tag of another release line #300).open-java-format,-spiand-jdk-bootstrap17.1.0 on Maven Central, the Gradle plugin with its four IDs on the Plugin Portal, where the latest version stays 21.1.2, and the GitHub release with the runnable jar and the Gradle plugin's jar, not marked Latest.src.zipand 400 sources jars, 17.1.0 on JDK 17 and 21.1.2 on JDK 21 give the same output. A;between imports fails withextraneous semicolonat the same place.dev.openjavaformat.java-format17.1.0 runsformatDiffon the Gradle JVM, and withopenjavaformat.native.formatter.version=21.1.2through the 21.1.2 native binary. Maven with the Spotless plugin 3.12.0 anddev.openjavaformat:open-java-format:17.1.0passesspotless:checkon a file that 21.1.2 formatted, fails on an unformatted one, andspotless:applygives 21.1.2's output.Still open: