Skip to content
Latchkey

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.

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.

gradle.properties
# gradle.properties
kotlin.daemon.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m
org.gradle.jvmargs=-Xmx2g

Reduce concurrent memory or run in-process

  1. Lower org.gradle.workers.max so fewer JVMs compete for RAM.
  2. Use a larger runner for memory-heavy Kotlin modules.
  3. 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →