Gradle Toolchain Auto-Provisioning Failed - Fix JDK Download in CI
Gradle tried to auto-provision a JDK for a Java toolchain and could not. Either no local JDK matched and the download failed (a transient network/provider blip), or no toolchain download repository is configured so Gradle has nowhere to fetch from.
What this error means
The build fails resolving a toolchain with Unable to download toolchain matching the requirements (languageVersion=21, ...), or No matching toolchains found ... and auto-provisioning failed / Toolchain download repositories have not been configured.
> Could not determine the dependencies of task ':app:compileJava'.
> Failed to calculate the value of task ':app:compileJava' property 'javaCompiler'.
> Unable to download toolchain matching the requirements
({languageVersion=21, vendor=any, implementation=vendor-specific}) ...
> Read timed outCommon causes
Transient download failure from the toolchain provider
Auto-provisioning downloads a JDK from a remote provider (e.g. the Foojay resolver). A network blip or provider slowness times out the fetch - usually clears on retry.
No toolchain download repository configured
Modern Gradle requires a toolchain resolver plugin (e.g. foojay-resolver-convention) in settings. Without it, no local match means auto-provisioning has no source and fails hard.
How to fix it
Configure a toolchain resolver and provide the JDK in CI
Add the Foojay resolver in settings and pre-install the JDK so provisioning can match locally without a download.
// settings.gradle.kts
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}Pre-provision the toolchain JDK to avoid a live download
Install the JDK with setup-java and let Gradle detect it instead of downloading.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- run: ./gradlew build -Dorg.gradle.java.installations.auto-download=falseHow to prevent it
- Add the foojay-resolver-convention plugin so toolchains can resolve.
- Pre-install toolchain JDKs in CI and let Gradle detect them (avoid live downloads).
- Cache
~/.gradle/jdksso a provisioned toolchain is reused across jobs.