Repository navigation
Pin the Java toolchain to JDK 21 using java { toolchain {…} } - #4366
Merged
Merged
Conversation
* 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.
alecgrieser
approved these changes
Jul 21, 2026
alecgrieser
left a comment
Collaborator
There was a problem hiding this comment.
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
toolchain { languageVersion = … }to reliably pin the Java toolchain to JDK 21. This decouples the build from whatever JDK the developer happens to have onPATH.JavaVersion.current().isCompatibleWith(VERSION_17)guard. It is no longer necessary because the toolchain already ensures an appropriate JDK will be used.options.release = 17to everyJavaCompiletask. Previously it was onlycompileJava, so tests were actually targeting Java 21.PendingWritesQueueConcurrencyTest, remove an inadvertent dependency on the JDK 19 API (namely, a try-with-resources statement taking advantage ofExecutorServicebeing 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
javacarguments.