What is New in Kotlin 2.2
Kotlin 2.2 brings the new K2 compiler into stable use, making compilation faster and more consistent across platforms. It also stabilizes many features, introduces preview language improvements like context parameters, and adds better tools for multiplatform development, Gradle integration, and Compose. Overall, it focuses on performance, stability, and modern language capabilities.
K2 Compiler Now Stable
The Kotlin K2 compiler is the default in version 2.2. It delivers quicker compilation times, better code analysis, and uniform behavior on all targets including JVM, Native, JS, and Wasm. Developers benefit from reduced build times and fewer inconsistencies in multiplatform projects.
Language Features
Context Parameters (Preview)
A new way to declare implicit dependencies for functions and properties. It replaces context receivers and makes dependency injection clearer.
context(users: UserService)
fun outputMessage(message: String) {
users.log("Log: $message")
}
Context-Sensitive Resolution (Preview)
Shorten type references when the context already knows the type, leading to cleaner code.
Annotation Use-Site Targets (Preview)
New @all meta-target applies annotations to all relevant parts of properties. Updated default rules prioritize param, then property, then field.
Nested Type Aliases (Beta)
Define type aliases inside classes or interfaces for better organization.
class Dijkstra {
typealias VisitedNodes = Set<Node>
}
Stabilized Features
Guard conditions, non-local break and continue, and multi-dollar string interpolation are now fully stable.
Standard Library Updates
Stable Base64 API
Full support for encoding and decoding with schemes like Default, UrlSafe, Mime, and new Pem.
Base64.Default.encode("fo".toByteArray()) // "Zm8="
Stable HexFormat API
Convenient tools for converting numbers to hexadecimal strings and parsing them back.
JVM and Platform-Specific Changes
Kotlin/JVM
Stable control over default method generation with -jvm-default. Better Java interop for inline value classes using @JvmExposeBoxed. Improved annotation handling in metadata and for JVM records.
Kotlin/Native
Updated to LLVM 19 for performance gains. Experimental per-object allocation and Latin-1 strings options. Memory tagging enabled by default on Apple platforms. Windows 7 target deprecated.
Kotlin/Wasm
Separate build directories and per-project configuration for Binaryen.
Kotlin/JS
Fixes for copy() in plain objects, support for type aliases in JsModule, and better JsExport with expect declarations and Promise<Unit>.
Gradle and Build Tools
Binary Compatibility Validation (Experimental)
Check API stability across builds to catch breaking changes early.
Rich Console Output
Colorful and more informative logs in the terminal.
Problems API Integration
Structured diagnostics that work better with Gradle 8.6 and above.
Build Tools API (Experimental)
A new abstraction layer for custom build systems, starting with JVM support.
Compose Compiler Updates
Support for composable function references like ::Text. Several feature flags like PausableComposition and OptimizeNonSkippingGroups are now enabled by default. StrongSkipping and IntrinsicRemember are deprecated.
Deprecations and Breaking Changes
Older language versions (1.6 and 1.7) are no longer supported. The Ant build system, certain scripting features (REPL, JSR-223), and some Gradle DSL elements like kotlinOptions{} are deprecated. Many old compiler flags have stable replacements.
Final Thoughts
Kotlin 2.2 marks a major milestone with the stable K2 compiler and refined language tools. It improves speed, consistency, and developer productivity across JVM, Native, Web, and multiplatform projects. Teams can now adopt modern features confidently while preparing for future enhancements in the ecosystem.