Gradle "Unable to start the daemon" / Bad JVM Args - Fix in CI
The Gradle daemon JVM could not even start. The JVM args in org.gradle.jvmargs (or GRADLE_OPTS) request more memory than the runner has, or contain an invalid flag, so the process aborts at launch.
What this error means
Gradle fails before any build with Unable to start the daemon process and a JVM message such as Could not reserve enough space for object heap or Unrecognized VM option.
FAILURE: Build failed with an exception.
* What went wrong:
Unable to start the daemon process.
... Error occurred during initialization of VM
Could not reserve enough space for 4194304KB object heapCommon causes
org.gradle.jvmargs -Xmx exceeds runner RAM
A daemon -Xmx4g on a 2–3 GB runner cannot reserve its heap, so the daemon JVM aborts at startup.
Invalid or unrecognized JVM flag
A typo or a flag removed in the current JDK (e.g. an obsolete GC option) makes the JVM refuse to start.
How to fix it
Lower the daemon heap to fit the runner
Set org.gradle.jvmargs to a heap that fits, leaving room for the OS and forked workers.
# gradle.properties
org.gradle.jvmargs=-Xmx1536m -XX:MaxMetaspaceSize=512mValidate the JVM args
Check every source of daemon JVM args and remove invalid flags.
echo "$GRADLE_OPTS"
# test args against the runner JDK directly:
java -Xmx1536m -XX:MaxMetaspaceSize=512m -versionHow to prevent it
- Size
org.gradle.jvmargsto the runner RAM, not a fixed large value. - Audit GRADLE_OPTS and gradle.properties for stale or invalid flags.
- Test JVM args against the target JDK before pinning them.