Gradle "No matching toolchains found" - Fix Toolchain Resolution
Gradle’s Java toolchain feature was asked for a specific JDK (e.g. version 21) and could not find one installed, nor provision it. The build cannot select a compiler that matches your languageVersion.
What this error means
The build fails during configuration with No matching toolchains found for requested specification: {languageVersion=21, ...} and a note about auto-detection or auto-download. No JDK on the runner satisfies the request.
> Could not determine the dependencies of task ':app:compileJava'.
> No matching toolchains found for requested specification:
{languageVersion=21, vendor=any, implementation=vendor-specific}
for LINUX on x86_64.Common causes
Requested JDK not installed
The toolchain languageVersion does not match any JDK on the runner, and Gradle did not have one to auto-detect.
Auto-provisioning disabled or unreachable
If toolchain auto-download is off (or the download repository is unreachable in CI), Gradle cannot fetch the missing JDK and fails resolution.
How to fix it
Install the requested JDK in CI
Provision the exact JDK the toolchain asks for; setup-java exposes it for auto-detection.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
# Gradle auto-detects the installed JDK for the toolchainEnable toolchain auto-provisioning
Let Gradle download the JDK via the foojay resolver plugin 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.
- Add the foojay resolver so Gradle can auto-download when allowed.
- Keep
languageVersionaligned with a JDK you actually install.