Gradle cannot calculate the javaCompiler for compileJava
Failed to calculate the value of task ':compileJava' property 'javaCompiler'Short answer
The build asks for a Java toolchain version that Gradle cannot find on the machine. Either install that JDK where Gradle detects it, or add a toolchain resolver plugin to settings so Gradle can download it. Keep auto-download enabled on CI machines.
Fix it fast
1Find out which cause you have
List the JDKs Gradle detects, and whether auto-detection and auto-download are on.
./gradlew -q javaToolchains2Match what you see, then jump to its fix
- 1
The version in java.toolchain.languageVersion does not appear in the javaToolchains list.The requested JDK is not installed and no download repository is setFix - 2
javaToolchains shows auto-download disabled, or the property is set in gradle.properties or on the command line.Auto-download is switched off, for example on a CI agentFix
- 1
What does the error look like?
Failed to calculate the value of task ':compileJava' property 'javaCompiler'
Cause 1 of 2
The requested JDK is not installed and no download repository is set
1Check
Gradle only downloads a missing JDK when a toolchain download repository is configured in the settings file. Compare the requested version in the build with the list from the first step.
grep -rn "languageVersion\|jvmToolchain" build.gradle* app/build.gradle* 2>/dev/null2Fix
Apply the Foojay toolchain resolver plugin in settings.gradle(.kts) so Gradle can fetch the JDK. Version 1.0.0 needs Java 17 or later and Gradle 7.6 or later.
// settings.gradle.kts
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
}3Verify
Run the compile task; Gradle downloads the JDK once and reuses it.
./gradlew compileJavaConfirmed by docs.gradle.org
Cause 2 of 2
Auto-download is switched off, for example on a CI agent
1Check
The properties org.gradle.java.installations.auto-download and org.gradle.java.installations.auto-detect turn provisioning and local detection off.
grep -rn "org.gradle.java.installations" gradle.properties ~/.gradle/gradle.properties2Fix
Either remove the property, or install the JDK yourself and stop the old daemons so the change is picked up. Point Gradle at a non-default location with org.gradle.java.installations.paths.
# gradle.properties
org.gradle.java.installations.paths=/opt/jdks/jdk-21
./gradlew --stop3Verify
The JDK now shows in the toolchain list.
./gradlew -q javaToolchainsConfirmed by docs.gradle.org
How do I stop it coming back?
- Declare the toolchain version once in the build and the resolver once in settings, so every machine behaves the same.
- Run ./gradlew javaToolchains on a fresh CI agent when you change the requested version.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
Gradle runs no Cucumber scenarios from my feature files
Feature files exist under src/test but nothing runs
Cucumber runs on the JUnit Platform, so Gradle must call useJUnitPlatform() and have the cucumber-junit-platform-engine on the test classpath.
4 causes, each with a fixBack end
A Gradle build fails on classes that use Lombok annotations
Error: Annotation processors must be explicitly declared now.
Lombok is two things for Gradle: a compile-time library and an annotation processor.
3 causes, each with a fixBack end
Gradle cannot find org.codehaus.groovy:groovy for a Groovy 4 version
Could not find org.codehaus.groovy:groovy:4.0.12.
Groovy 4 and newer are published under the group org.apache.groovy.
2 causes, each with a fixBack end
A JaCoCo report setting that worked in Gradle 7 fails in Gradle 8
Report property destination no longer exists after the Gradle 8 upgrade
Gradle 8.0 removed the enabled and destination properties of report objects.
2 causes, each with a fixBack end
Gradle 8 fails on Report destination: switch to outputLocation
What went wrong: 'java.io.File org.gradle.api.reporting.ConfigurableReport.getDestination()'
Gradle 8.0 removed the deprecated destination and enabled properties of the Report type.
2 causes, each with a fix