Gradle Kotlin "Daemon compilation failed: insufficient memory" in CI
The Kotlin compile daemon ran out of memory while compiling. The e: Daemon compilation failed: insufficient memory message means the Kotlin daemon JVM hit its heap ceiling - common on large modules or memory-tight runners.
What this error means
Kotlin compilation fails with e: Daemon compilation failed: insufficient memory (often with an underlying OutOfMemoryError), and Gradle may note it is retrying or falling back. The Gradle daemon itself is fine - it is the Kotlin compile daemon that OOMed.
e: Daemon compilation failed: insufficient memory for the Java Runtime Environment
java.lang.OutOfMemoryError: Java heap space
at org.jetbrains.kotlin.daemon.KotlinCompileDaemon ...
> Task :app:compileKotlin FAILEDCommon causes
Kotlin daemon heap too small
The Kotlin compile daemon runs in its own JVM with its own heap, separate from the Gradle daemon. A large module exceeds its default -Xmx and OOMs.
Runner memory exhausted by multiple JVMs
The Gradle daemon, the Kotlin daemon, and forked test JVMs together can exceed the runner RAM, leaving the Kotlin daemon unable to reserve its heap.
How to fix it
Raise the Kotlin daemon JVM heap
Set the Kotlin daemon options explicitly so it gets enough heap.
# gradle.properties
kotlin.daemon.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m
org.gradle.jvmargs=-Xmx2gReduce concurrent memory or run in-process
- Lower
org.gradle.workers.maxso fewer JVMs compete for RAM. - Use a larger runner for memory-heavy Kotlin modules.
- As a fallback, disable the Kotlin daemon (
kotlin.compiler.execution.strategy=in-process) so compilation shares the Gradle daemon heap.
How to prevent it
- Set
kotlin.daemon.jvmargsheap relative to the runner RAM. - Bound
org.gradle.workers.maxso concurrent JVMs do not exhaust memory. - Right-size the runner for large Kotlin modules.