Skip to content

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

Open
RobertBrunel wants to merge 1 commit into
FoundationDB:mainfrom
RobertBrunel:jdk21-toolchain
Open

Pin the Java toolchain to JDK 21 using java { toolchain {…} }#4366
RobertBrunel wants to merge 1 commit into
FoundationDB:mainfrom
RobertBrunel:jdk21-toolchain

Conversation

@RobertBrunel

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.
  • 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.

* 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.
@RobertBrunel RobertBrunel self-assigned this Jul 17, 2026
@RobertBrunel RobertBrunel added the build improvement Improvement to the build system label Jul 17, 2026
@RobertBrunel
RobertBrunel marked this pull request as ready for review July 17, 2026 14:38
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.

1 participant