Gradle "The Daemon will be stopped ... after the build due to low heap space" - Fix in CI
Gradle detected its daemon was nearly out of heap and announced it will stop the daemon after the build to avoid memory pressure. The build may still pass, but the daemon is recycled every run (no warm reuse) and is one spike away from an OutOfMemoryError.
What this error means
The log shows The Daemon will be stopped at the end of the build after running out of JVM heap space or expiring Daemon because JVM heap space is exhausted. Builds are slow because the daemon never stays warm; a slightly bigger build OOMs.
> Task :test
The message received from the daemon indicates that the daemon has disappeared.
...
The Daemon will be stopped at the end of the build after running out of JVM
heap space (low heap space detected; consider increasing org.gradle.jvmargs)Common causes
Daemon heap too small for the build
The default -Xmx is below what compilation, kapt, or large test runs need, so the daemon repeatedly nears exhaustion.
Memory-heavy plugins or codegen
Annotation processing, shadow/jib packaging, or large dependency graphs push heap use past the limit.
Undersized runner
A small runner cannot give the daemon enough RAM, so even a modest build trips the low-heap guard.
How to fix it
Raise the daemon heap
Give the Gradle daemon more heap and metaspace via gradle.properties.
# gradle.properties
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryErrorCap test/worker forks
Bound forked memory so parallel test workers do not starve the daemon.
test {
maxHeapSize = '1g'
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}Run on a larger runner
Match runner RAM to the build so the daemon stays warm.
# choose a higher-memory runner for heavy Gradle buildsHow to prevent it
- Set an explicit
org.gradle.jvmargsheap sized to your build. - Bound test fork count and per-fork heap.
- Right-size runners for memory-heavy Gradle builds.