java
path_handling
ai_generated
true
Gradle build fails: Could not determine java version — JAVA_HOME path has spaces
ID: java/gradle-space-in-java-home
88%Fix Rate
90%Confidence
4Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 8 | active | — | — | — |
Root Cause
Gradle build fails when JAVA_HOME or project path contains spaces, especially on Windows with backslash paths.
genericWorkarounds
-
93% success Install JDK to a path without spaces (e.g., /opt/jdk17 or C:\jdk17)
export JAVA_HOME=/opt/jdk-17 # avoid 'Program Files' or any path with spaces
Sources: https://docs.gradle.org/current/userguide/build_environment.html
-
88% success Use org.gradle.java.home in gradle.properties with forward slashes and no spaces
org.gradle.java.home=C:/jdk-17 # use forward slashes, no spaces in path
Sources: https://docs.gradle.org/current/userguide/build_environment.html
Dead Ends
Common approaches that don't work:
-
Quote JAVA_HOME in gradle.properties
90% fail
gradle.properties does not interpret shell quotes; the literal quote characters become part of the path
-
Set JAVA_HOME with Windows short name (PROGRA~1)
65% fail
Short names are not always enabled on all volumes and may not resolve correctly