Gradle "No locally installed toolchains match" - Fix JDK Toolchain in CI
Your build asked for a specific Java toolchain (e.g. language version 21) and Gradle could not find a matching JDK on the runner. With auto-detection or auto-download disabled, no JDK satisfied the request, so the build cannot select a compiler.
What this error means
The build fails with No matching toolchains found for the requested specification and No locally installed toolchains match (and toolchain auto-provisioning is not enabled), naming the requested version (e.g. {languageVersion=21, ...}).
* What went wrong:
Could not determine the dependencies of task ':app:compileJava'.
> Failed to calculate the value of task ':app:compileJava' property 'javaCompiler'.
> No matching toolchains found for the requested specification:
{languageVersion=21, vendor=any, implementation=vendor-specific}.
No locally installed toolchains match and toolchain download repositories
have not been configured.Common causes
Requested JDK not installed on the runner
The java.toolchain { languageVersion = 21 } needs a JDK 21 present. If CI only provisioned JDK 17, no local toolchain matches.
Auto-provisioning disabled with no download repo
Toolchain download requires a configured provisioning repository (e.g. the Foojay resolver) and network access. Disabled or unconfigured, Gradle cannot fetch the missing JDK.
How to fix it
Provision the requested JDK in CI
Install the JDK the toolchain asks for so a local toolchain matches. setup-java exposes it for auto-detection.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21' # satisfies languageVersion = 21Enable toolchain auto-provisioning
Add the Foojay toolchains resolver so Gradle can download a matching JDK when none is installed.
// settings.gradle.kts
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}How to prevent it
- Provision the toolchain JDK in CI with setup-java, and let Gradle auto-detect it.
- Add the Foojay resolver so a missing toolchain can be downloaded.
- Keep
languageVersionaligned with a JDK that CI actually installs.