Skip to content

A 17.X.X release line: the formatter and the Gradle plugin on Java 17, backported from 21.X.X #293

Done

Description

@abashev

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:

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-bootstrap and the Gradle plugin gradle-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. On 17.X.X they stay in the tree, commented out in settings.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.toml installs Temurin 17, and gradle.properties reads JDK17_HOME instead of JDK21_HOME and GRAALVM_HOME. javac 17 itself rejects the syntax and the APIs newer than Java 17, so there is no -source/-target trick 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.2 that 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 switch over BreakBehaviour in BreakBehaviour.java and doc/Level.java, the type patterns in switch in the Gradle plugin's XmlUtils.java, ExecutorService as a try-with-resources resource in Main.java (AutoCloseable since Java 19), and List.getFirst()/getLast() in the test helper CaseFile.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.
  • FormatterCasesJava21Test is enabled from JDK 21 only (ADR-002), so the trial above did not run the 918 case files of test-cases-java21 at all. Run on JDK 17, 891 of them give the 21 line's expected output through Java14InputAstVisitor, and on JDK 21 the same 17-target classes pass all 918 through Java21InputAstVisitor; 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 to test-cases-java17/, run through the visitor of JDK 17 on every JDK by a FormatterCasesJava17Test with no JRE condition (17 is JUnit 6's floor), and left the 9 in test-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-replacements and the command line's range output, as nothing else does on JDK 17. The 17 line then runs test-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, Formatter picks 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 merged Java14InputAstVisitor, up to JDK 20, and Java21InputAstVisitor, 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 compile Java21InputAstVisitor, so 17.X.X deletes it and Formatter takes JavaInputAstVisitor on every JDK. On JDK 21 and later, which the 17 line does not test, 17.x formats Java 17 syntax through it; FormatterCasesJava17Test checks 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 of open-java-format-native the 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 for open-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:

  • build on 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 jdk matrix (25, 26, 27, 28-ea), no native and no wasm: the line builds no image;
  • the ruleset "Default branch" covers 21.X.X only, so the ruleset 17.X.X gives the branch the same rules: pull requests, signed commits, build, no force push, no deletion;
  • Dependabot and update-pr-branch.yml stay 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 palantirJavaFormat step inside the build's JVM, and a Gradle plugin built for 21 cannot even be applied on 17. Spotless's nativeCmd step 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) and test-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), and 17.X.X is cut from it (done at a884c7b) with the rules of 21.X.X, its build on JDK 17 only;
  • ./gradlew check passes on JDK 17 alone, every class of 17.1.0 is class file 61, and on JDK 17 the cases of test-cases-java17/ pass and a ; between imports fails with extraneous semicolon, as on 21.x;
  • a 17.1.0 tag publishes open-java-format, -spi and -jdk-bootstrap 17.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.zip and the Gradle sources jars;
  • on JDK 17, dev.openjavaformat.java-format 17.1.0 applies and formatDiff runs in a Gradle 9 build, and Spotless 3.12.0 with groupArtifact dev.openjavaformat:open-java-format and version 17.1.0 passes spotless:check on a project that 21.1.2 formatted; with openjavaformat.native.formatter.version=21.1.2, the 17.1.0 plugin formats with the 21.1.2 native image;
  • fmt-maven-plugin runs check on 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

  1. added
    enhancement
    on Nov 28, 2026
  2. changed the title [-]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[/+] on Nov 29, 2026
  3. abashev commented on Dec 1, 2026

    @abashev
    CollaboratorAuthor

    17.1.0 is out.

    • Branch. 17.X.X builds, 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).
    • Published. open-java-format, -spi and -jdk-bootstrap 17.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.
    • Same output. On 76,612 files, the JDK 17 src.zip and 400 sources jars, 17.1.0 on JDK 17 and 21.1.2 on JDK 21 give the same output. A ; between imports fails with extraneous semicolon at the same place.
    • Checked on JDK 17 with the published artifacts. Gradle 9.9.1 with dev.openjavaformat.java-format 17.1.0 runs formatDiff on the Gradle JVM, and with openjavaformat.native.formatter.version=21.1.2 through the 21.1.2 native binary. Maven with the Spotless plugin 3.12.0 and dev.openjavaformat:open-java-format:17.1.0 passes spotless:check on a file that 21.1.2 formatted, fails on an unformatted one, and spotless:apply gives 21.1.2's output.

    Still open:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions