Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle cannot find the java executable in the configured Java home

ErrorThe supplied javaHome seems to be invalid. I cannot find the java executable.

Short answer

Gradle takes its Java home from a command-line option, then from org.gradle.java.home in gradle.properties, then from JAVA_HOME. If the highest one points to a folder with no bin/java inside, the build fails. Find which setting wins, fix the path to a real JDK folder, or remove the stale setting.

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

Fix it fast

  1. 1Find out which cause you have

    Look for every place the Java home is set, in the order Gradle reads them.

    grep -rn "org.gradle.java.home" gradle.properties ~/.gradle/gradle.properties
    echo $JAVA_HOME
  2. 2Match what you see, then jump to its fix

    1. 1The tried location in the message matches a path in gradle.propertiesorg.gradle.java.home points to a folder that no longer existsFix
    2. 2No org.gradle.java.home is set, and the tried location matches JAVA_HOMEJAVA_HOME points to a wrong folderFix

What does the error look like?

  • The supplied javaHome seems to be invalid. I cannot find the java executable.
  • Tried location: C:\Program Files\Java\jdk-17\bin\java.exe

Cause 1 of 2

org.gradle.java.home points to a folder that no longer exists

1Check

Gradle's documentation says org.gradle.java.home in gradle.properties sets the Java home for the build and ranks above JAVA_HOME. A JDK that was uninstalled or moved leaves this path dangling.

grep -rn "org.gradle.java.home" gradle.properties ~/.gradle/gradle.properties

2Fix

Set it to the real JDK folder, the one that contains bin/java, or delete the line to fall back to JAVA_HOME.

# gradle.properties
org.gradle.java.home=C:/Program Files/Java/jdk-17

3Verify

Stop old daemons and run a build.

./gradlew --stop
./gradlew --version

Confirmed by docs.gradle.org

Did this fix it?

Cause 2 of 2

JAVA_HOME points to a wrong folder

1Check

JAVA_HOME names the JDK installation directory for the client VM. Check that the java executable exists inside it.

echo $JAVA_HOME
ls "$JAVA_HOME/bin/java"

2Fix

Point JAVA_HOME at an installed JDK folder and open a new terminal so it is picked up. Also check the command-line option -Dorg.gradle.java.home, which beats both.

export JAVA_HOME=/path/to/jdk-17

3Verify

Gradle starts and reports its JVM.

./gradlew --version

Confirmed by docs.gradle.org

Did this fix it?

How do I stop it coming back?

  • Avoid hard-coding org.gradle.java.home in a file shared with other machines.
  • After upgrading or removing a JDK, search gradle.properties files for its old path.

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

Mobile apps

Android app crashes because the Apache HTTP classes are missing

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;

From Android 9 the Apache HTTP client is no longer on the default classpath, so code or a library that still uses org.apache.http fails at runtime.

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