Kotlin 2.1 Released: What's New in the Language and Tools
On November 16, 2024, JetBrains released the stable version of Kotlin 2.1.0 — a major update that continues the language's development after the revolutionary transition to the K2 compiler in version 2.0. The new release not only fixes bugs but also introduces a number of long-awaited experimental features. We break down the main changes for developers.
K2 Stabilization: What It Means for Developers
The main news is that the K2 compiler, which was optional in Kotlin 2.0, has now become the default for JVM and multiplatform projects. K2 provides:
- Significant build speed improvements (up to 2–3 times on large projects);
- Improved type inference — fewer explicit annotations;
- More accurate and understandable error messages;
- Full support for Kotlin Multiplatform (KMP) and Compose Multiplatform.
For developers using Gradle, simply update the Kotlin plugin to version 2.1.0 — K2 activates automatically.
New Experimental Language Features
Version 2.1 introduces several preview features, accessible via the @OptIn annotation. Here are the most interesting ones:
- Non-local break/continue — you can now use
breakandcontinueinside lambda expressions passed to inline functions. This simplifies working with loops in a functional style. - Explicit backing fields — a new construct for direct access to a property's field inside a getter/setter without recursion. Simplifies writing delegated properties.
- Named arguments in lambda — experimental support for named arguments for lambda parameters. Makes code with multiple lambdas more readable.
Improvements for Kotlin Multiplatform
Kotlin 2.1 is an important step for multiplatform development. Key changes:
- Full support for expect/actual for standard libraries — you can now declare platform-dependent functions directly in commonMain.
- Improved integration with CocoaPods and Swift Package Manager for iOS targets.
- New configuration mode for Android: automatic source set setup for modern AGP (Android Gradle Plugin) 8.x.
Updates in Compose Multiplatform
For UI application developers, the release introduces support for Resource API — a new way to work with resources (images, strings, fonts) in Compose Multiplatform. Resources can now be placed in a common module, and the plugin automatically generates type-safe references for each platform. This simplifies creating cross-platform applications with a unified rendering logic.
How to Update to Kotlin 2.1
The update is trivial for Gradle projects. Add to build.gradle.kts:
plugins { kotlin("jvm") version "2.1.0" // or kotlin("multiplatform") version "2.1.0"}JetBrains recommends running the project with the --warning-mode all flag before updating to check compatibility with the new compiler. For Int