Gradle Kotlin "Daemon compilation failed: insufficient memory" in CI
By Kaveh Alemi·Latchkey
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.
gradle output
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 FAILED
Common 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.
Lower org.gradle.workers.max so 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.jvmargs heap relative to the runner RAM.
Bound org.gradle.workers.max so concurrent JVMs do not exhaust memory.
Right-size the runner for large Kotlin modules.
Frequently asked questions
What causes ""Daemon compilation failed: insufficient memory""?
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.
How do I fix "Daemon compilation failed: insufficient memory"?
Set the Kotlin daemon options explicitly so it gets enough heap.
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.