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

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
4Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8 active

Root Cause

Gradle build fails when JAVA_HOME or project path contains spaces, especially on Windows with backslash paths.

generic

Workarounds

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

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

  1. Quote JAVA_HOME in gradle.properties 90% fail

    gradle.properties does not interpret shell quotes; the literal quote characters become part of the path

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