Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Gradle cannot calculate the javaCompiler for compileJava

ErrorFailed 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.

  • Applies to Gradle 8 and 9, JDK 17 and 21
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the JDKs Gradle detects, and whether auto-detection and auto-download are on.

    ./gradlew -q javaToolchains
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2javaToolchains 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

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/null

2Fix

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 compileJava

Confirmed by docs.gradle.org

Did this fix it?

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.properties

2Fix

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 --stop

3Verify

The JDK now shows in the toolchain list.

./gradlew -q javaToolchains

Confirmed by docs.gradle.org

Did this fix it?

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

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.