Skip to content

Pin the Java toolchain to JDK 21 using java { toolchain {…} } - #4366

Merged
robert-brunel merged 1 commit into
FoundationDB:mainfrom
robert-brunel:jdk21-toolchain
Jul 21, 2026
Merged

robert-brunel merged 1 commit into
FoundationDB:mainfrom
robert-brunel:jdk21-toolchain

Conversation

@robert-brunel

@robert-brunel robert-brunel commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor
  • Use toolchain { languageVersion = … } to reliably pin the Java toolchain to JDK 21. This decouples the build from whatever JDK the developer happens to have on PATH.
  • Disable auto-provisioning of JDKs. Gradle will pick a matching JDK from its detected local JDK installations.
  • Drop the manual JavaVersion.current().isCompatibleWith(VERSION_17) guard. It is no longer necessary because the toolchain already ensures an appropriate JDK will be used.
  • Apply options.release = 17 to every JavaCompile task. Previously it was only compileJava, so tests were actually targeting Java 21.
  • In PendingWritesQueueConcurrencyTest, remove an inadvertent dependency on the JDK 19 API (namely, a try-with-resources statement taking advantage of ExecutorService being auto-closeable) in order to make it compile under --release 17.

Apart from pinning the JDK cleanly, toolchains also interact better with the Build Cache. Gradle folds the toolchain JDK identity into the build cache key, so cached compile outputs are tied to the JDK that produced them rather than just to javac arguments.

* Use `toolchain { languageVersion = … }` to reliably pin the Java toolchain to JDK 21. This decouples the build from whatever JDK the developer happens to have on `PATH`.
* Disable auto-provisioning of JDKs. Gradle will pick a matching JDK from its detected local JDK installations.
* Drop the manual `JavaVersion.current().isCompatibleWith(VERSION_17)` guard. It is no longer necessary because the toolchain already ensures an appropriate JDK will be used.
* Apply `options.release = 17` to **every** `JavaCompile` task. Previously it was only `compileJava`, so tests were actually targeting Java 21.
* Remove a JDK 19 dependency from `PendingWritesQueueConcurrencyTest` to make it compile under `--release 17`.

Apart from pinning the JDK cleanly, toolchains also interact better with the Build Cache. Gradle folds the toolchain JDK identity into the build cache key, so cached compile outputs are tied to the JDK that produced them rather than just to `javac` arguments.
@robert-brunel robert-brunel self-assigned this Jul 17, 2026
@robert-brunel robert-brunel added the build improvement Improvement to the build system label Jul 17, 2026
@robert-brunel
robert-brunel marked this pull request as ready for review July 17, 2026 14:38

@alecgrieser alecgrieser left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I did have a question about the necessity of the PendingWritesQueueConcurrencyTest that it would be good to get spelled out (if only in the PR description or in response to my comment--I don't think it needs a code change)

@robert-brunel
robert-brunel merged commit a8ce88f into FoundationDB:main Jul 21, 2026
33 of 35 checks passed
@robert-brunel
robert-brunel deleted the jdk21-toolchain branch July 21, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build improvement Improvement to the build system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants