Skip to content
Latchkey

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, ...}).

gradle output
* 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.

.github/workflows/ci.yml
- uses: actions/setup-java@v4
  with:
    distribution: temurin
    java-version: '21'   # satisfies languageVersion = 21

Enable toolchain auto-provisioning

Add the Foojay toolchains resolver so Gradle can download a matching JDK when none is installed.

settings.gradle.kts
// 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 languageVersion aligned with a JDK that CI actually installs.

Frequently asked questions

What causes ""No locally installed toolchains match""?
The java.toolchain { languageVersion = 21 } needs a JDK 21 present. If CI only provisioned JDK 17, no local toolchain matches.
How do I fix "No locally installed toolchains match"?
Install the JDK the toolchain asks for so a local toolchain matches. setup-java exposes it for auto-detection.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card