Kotlin 2.5.0-Beta1 introduces an optional separate compilation scheme for Kotlin Multiplatform (KMP) projects. The experimental feature is designed to reduce cases where IntelliJ IDEA and the compiler resolve shared code differently, while also enabling incremental compilation for common source sets.
A stricter boundary
Under the current scheme, common source sets can be compiled against platform artifacts from dependencies. That can allow commonMain or commonTest code to resolve declarations that exist only in a platform source set, even when the IDE marks the reference as unresolved. Separate compilation instead resolves common code against the dependency’s metadata KLIB, which contains declarations from shared source sets without their bodies.
What changes for developers
The new mode makes the compiler follow the same shared-code boundary that IDE analysis already assumes. Calls from commonMain to platform-only declarations will become compilation errors rather than silently resolving for a target such as Kotlin/JVM. Developers who intentionally expose platform behavior must represent the relationship explicitly with expect declarations in commonMain and actual declarations in the relevant platform source set.
The change also affects overload resolution. If common and platform source sets provide different overloads, separate compilation selects the declaration visible from common code instead of allowing a more specific platform overload to change the runtime result. In another example described by JetBrains, resolving common code before platform compilation preserves an expected return type when platform-specific supertypes would otherwise cause JVM compilation to infer Any.
How to opt in
The feature is disabled by default. Projects can enable it by adding kotlin.kmp.separateCompilation=true to gradle.properties. Existing projects may need code changes because checks that previously passed during compilation can become errors under the stricter rules.
Known limitations
Separate compilation depends on multiplatform libraries publishing metadata KLIBs, which the KMP Gradle plugin publishing tasks do by default. JetBrains also lists unresolved issues involving commonization of C interop, including KT-88178 and KT-41509, and notes that KMP modules with common source sets and only one declared target are not affected for now. Other smaller issues, including KT-88148, remain open.
AI-generated editorial illustration; not a documentary photograph.
Source: A More Reliable Compilation Scheme for Kotlin Multiplatform Modules

Leave a Reply