Skip to content
Latchkey

Gradle "Daemon compilation failed" (Kotlin) - Fix Kotlin Daemon in CI

The Kotlin compile daemon failed - it crashed mid-compile (frequently OOM) or Gradle could not connect to it. The Kotlin compiler runs in its own daemon process, separate from the Gradle daemon.

What this error means

A Kotlin compile task fails with Daemon compilation failed or Could not connect to Kotlin compile daemon, sometimes with a fallback message. No source error is shown - the daemon process itself died.

gradle output
> Task :app:compileKotlin FAILED
e: Daemon compilation failed: null
java.lang.Exception
# or
Could not connect to Kotlin compile daemon

Common causes

Kotlin daemon ran out of memory

The Kotlin daemon has its own JVM. On a memory-tight runner it can OOM and die, failing the compile with no source-level error.

Daemon could not start or connect

Sandboxing, a stale daemon, or a too-restrictive environment can prevent Gradle from launching or connecting to the Kotlin daemon.

How to fix it

Give the Kotlin daemon more memory

Set Kotlin daemon JVM args so it has enough heap to compile.

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

Run the Kotlin compiler in-process

Disabling the daemon avoids connect/crash issues at some performance cost - useful in constrained CI.

Terminal
./gradlew compileKotlin -Pkotlin.compiler.execution.strategy=in-process
# or gradle.properties: kotlin.compiler.execution.strategy=in-process

How to prevent it

  • Set kotlin.daemon.jvmargs relative to the runner RAM.
  • Use in-process compilation in tight CI environments.
  • Right-size the runner for memory-heavy Kotlin modules.

Related guides

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