Compiler execution strategy
The Kotlin compiler execution strategy defines where the Kotlin compiler runs. Build tools such as Gradle or Maven configure the strategy.
There are two compiler execution strategies:
Strategy | Where the Kotlin compiler runs | Other characteristics and notes |
|---|---|---|
Inside its own daemon process | The default and fastest strategy in Gradle and Maven. The daemon process can be shared between different build system processes and multiple parallel compilations. | |
In process | Inside the build tool's process | The simplest strategy from the perspective of memory management, but it's less isolated from other logic running in the same process because it shares state, such as JVM system properties. |
Configure in Gradle
You can define the Kotlin compiler execution strategy using one of the following properties:
The
kotlin.compiler.execution.strategyGradle property.The
compilerExecutionStrategycompile task property.
Use the Gradle property
The possible values for the kotlin.compiler.execution.strategy property are:
daemon(default)in-process
Set the kotlin.compiler.execution.strategy property in gradle.properties:
Use the compile task property
The compilerExecutionStrategy task property takes priority over the kotlin.compiler.execution.strategy Gradle property.
The possible values for the compilerExecutionStrategy task property are:
DAEMON(default)
Set the compilerExecutionStrategy task property in your build scripts:
Fallback strategy
If communication with the Kotlin daemon fails, the compiler falls back to the "In process" strategy.
When this fallback happens, Gradle prints the following warning in the build output:
A silent fallback can consume a lot of system resources or lead to non-deterministic builds. For more information, see this YouTrack issue.
To prevent fallback, use the kotlin.daemon.useFallbackStrategy Gradle property. The default value is true. When set to false, builds fail if there are problems with the daemon's startup or communication. Declare this property in gradle.properties:
There is also a useDaemonFallbackStrategy property in Kotlin compile tasks. If you use both properties, the useDaemonFallbackStrategy property takes priority.
If there is not enough memory to run the compilation, the logs show a related message.
Configure in Maven
By default, Maven uses the Kotlin daemon compiler execution strategy. To switch to the "in process" strategy, set the following property in your pom.xml file: