Kotlin compile daemon terminated unexpectedly in CI
The Kotlin Gradle plugin compiles in a separate daemon process. When that process is killed (OOM killer, resource limit, or a crash), Gradle reports the daemon terminated and either falls back to in-process compilation or fails. On constrained CI runners this is usually a memory problem.
What this error means
The Kotlin compile task logs "Kotlin compile daemon is ready" then "Kotlin compile daemon terminated unexpectedly" or "Could not connect to Kotlin compile daemon", and the build slows down or fails.
w: Kotlin compile daemon terminated unexpectedly
Could not connect to Kotlin compile daemon, using non-daemon strategy.Common causes
The daemon JVM ran out of memory and was killed
On a small runner the daemon exceeds its heap or the container memory limit, and the OS kills it, so Gradle loses the connection.
A stale or crashed daemon from a prior run
A leftover daemon on a reused self-hosted runner is in a bad state, so the new build cannot connect to it.
How to fix it
Raise the Kotlin daemon JVM memory
Give the daemon and Gradle enough heap in gradle.properties so the daemon is not killed under load.
# gradle.properties
org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=1g
kotlin.daemon.jvmargs=-Xmx2gFall back to in-process compilation on tiny runners
If memory is very tight, run the Kotlin compiler in the Gradle process instead of a separate daemon.
./gradlew build -Dkotlin.compiler.execution.strategy=in-processHow to prevent it
- Size
kotlin.daemon.jvmargsandorg.gradle.jvmargsfor the runner memory. - Use runners with enough RAM for the Kotlin daemon plus Gradle.
- Avoid reusing dirty self-hosted runners; start each job with a clean daemon state.