cicd build ai_generated true

org.gradle.launcher.daemon.server.DaemonExpirationPeriodicCheck: Daemon will be stopped at the end of the build after running out of JVM heap space

ID: cicd/gradle-daemon-oom

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
any active

Root Cause

The Gradle daemon runs out of JVM heap memory during builds, commonly in CI environments with constrained resources. Large projects, annotation processing, and Kotlin compilation are major memory consumers.

generic

Workarounds

  1. 88% success Configure appropriate JVM memory settings in gradle.properties
    In gradle.properties: org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError. Ensure the heap size fits within the CI runner's memory limit with headroom for OS and other processes.
  2. 85% success Disable daemon and use --no-daemon with appropriate direct JVM memory
    In CI, add --no-daemon to Gradle commands and set GRADLE_OPTS='-Xmx2g'. This avoids daemon memory accumulation across builds and gives predictable memory usage per build.

Dead Ends

Common approaches that don't work:

  1. Disabling the Gradle daemon in CI without adjusting JVM args 70% fail

    Running without a daemon (--no-daemon) creates a new JVM for each build. Without increasing memory for the direct JVM, builds still OOM since the same workload needs the same memory.

  2. Setting extremely large heap sizes (e.g., -Xmx8g) on a 4GB CI runner 85% fail

    If the JVM heap exceeds the container memory limit, the container runtime (Docker/K8s) kills the process via OOM killer, producing a more cryptic exit code 137 error

Error Chain

Leads to:
Preceded by:
Frequently confused with: