Skip to content

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

Backlog

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 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-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, left out of settings.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 JavaCompile gets sourceCompatibility and targetCompatibility 17 and no --release (which javac refuses next to the --add-exports of jdk.compiler). Every class comes out as class file 61, Java21InputAstVisitor included, and Gradle Module Metadata says org.gradle.jvm.version 17. 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 released gradle-open-java-format:21.0.2. The tests run on JDK 17. mise.toml installs Temurin 21 and 17, and gradle.properties reads JDK21_HOME and JDK17_HOME instead of JDK21_HOME and GRAALVM_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 17 still rejects Java 21 syntax, but takes Java 18+ APIs against its own class library. A compileJava17Check task in check compiles each module's main sources once more with javac 17, without the java21 package 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 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 for JDK 21, 25 and 28 stay and skip themselves on 17.
  • 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). Before 17.X.X is cut again, 21.X.X moves the cases javac 17 parses to test-cases-java17/, run by a FormatterCasesJava17Test with no JRE condition (17 is JUnit 6's floor), and leaves the 9 in test-cases-java21/, with ADR-002 amended to match. 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.
  • Formatter picks the visitor by the running JDK and loads Java21InputAstVisitor by name on 21 and later (Formatter.java#L143-L149), and both lines keep that. On 21.X.X, with the case split, Java14InputAstVisitor becomes Java17InputAstVisitor, the visitor for JDK 17 to 20, and Formatter chooses between it and Java21InputAstVisitor only. The 17.x jar carries both: on JDK 17 it formats through Java17InputAstVisitor, and on 21 and later, which the 17 line does not test, through Java21InputAstVisitor, 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: NativeImageFormatProviderPlugin resolves open-java-format-native at the plugin's own version, and the 17 line publishes none. With openjavaformat.native.formatter=true the 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:

  • 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 17.X.X gets 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), 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 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 has Java17InputAstVisitor and runs its cases from test-cases-java17/ (on every JDK) and test-cases-java21/, and 17.X.X is cut from it with the rules of 21.X.X, its build on JDK 17 only;
  • every class of 17.1.0 is class file 61, compileJava17Check passes, 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;
  • 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
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