Skip to content
Latchkey

Java Heap Space During Gradle Build - Tune Daemon Heap in CI

The Gradle daemon JVM ran out of heap while configuring or executing a large build. A big project graph, many subprojects, or heavy configuration logic exceeded the daemon heap.

What this error means

A large multi-module build fails with java.lang.OutOfMemoryError: Java heap space attributed to the daemon, often during configuration before any task output appears.

gradle output
FAILURE: Build failed with an exception.
* What went wrong:
java.lang.OutOfMemoryError: Java heap space
  (during configuration of a 40-module build)

Common causes

Daemon heap too small for the graph

Many subprojects and a large dependency graph need more heap than the default. The daemon exhausts -Xmx while building the model.

Heavy configuration-time work

Eager configuration, large extensions, or plugins doing work at configuration time inflate the daemon heap before tasks even run.

How to fix it

Raise the daemon heap

Give the daemon enough heap for the project graph in gradle.properties.

gradle.properties
# gradle.properties
org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=1g
org.gradle.workers.max=2

Reduce configuration-time cost

  1. Enable the configuration cache and lazy task configuration to cut configuration-time memory.
  2. Lower org.gradle.workers.max so fewer JVMs run concurrently.
  3. Use --no-daemon in CI so heap does not accumulate across builds.

How to prevent it

  • Size org.gradle.jvmargs to the project graph, prefer lazy/configuration-cache builds, and use a larger runner for large multi-module projects.

Frequently asked questions

What causes "Daemon "Java heap space" during build"?
Many subprojects and a large dependency graph need more heap than the default. The daemon exhausts -Xmx while building the model.
How do I fix Daemon "Java heap space" during build?
Give the daemon enough heap for the project graph in gradle.properties.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card