Gradle Toolchain "No compatible toolchains found" (Detection) - Fix in CI
Gradle could not find an installed JDK matching a Java toolchain request, and auto-download is off (or could not run), so it failed. Unlike a download failure, this is purely about detection - the matching JDK is not installed where Gradle looks, and Gradle was told not to fetch one.
What this error means
The build fails with No compatible toolchains found for request specification: {languageVersion=21, ...} (auto-detect false, auto-download false). A JDK 21 may even be installed, but Gradle is not detecting it.
> No compatible toolchains found for request specification:
{languageVersion=21, vendor=any, implementation=vendor-specific}
(auto-detect false, auto-download false).Common causes
Requested JDK not installed where Gradle detects
The toolchain languageVersion has no matching JDK in Gradle’s detected installations, so there is nothing to select.
Auto-detect/auto-download disabled
With org.gradle.java.installations.auto-detect=false (or auto-download off) Gradle will neither scan standard locations nor fetch a JDK, so an uninstalled toolchain simply fails.
How to fix it
Install the JDK and point Gradle at it
Provision the requested JDK and pass its path via the installations property.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- run: ./gradlew build \
-Dorg.gradle.java.installations.paths=$JAVA_HOMERe-enable detection (or auto-download)
Let Gradle scan standard install locations, or allow it to download a matching JDK.
# gradle.properties
org.gradle.java.installations.auto-detect=true
# optionally allow download (needs a resolver plugin):
org.gradle.java.installations.auto-download=trueHow to prevent it
- Install the toolchain JDK in CI and pass
org.gradle.java.installations.paths. - Keep
auto-detecton, or configure a download resolver, so toolchains can resolve. - Assert the toolchain resolves early (e.g.
./gradlew javaToolchains).