2.0.21

Latest release in branch 2.0
Released 1 year ago (October 10, 2024)

Software Kotlin
Branch 2.0
Status
End of life
First official release version 2.0.0
First official release date 1 year ago (May 21, 2024)
Supported
Java versions
Java 22
Release notes https://github.com/JetBrains/kotlin/releases/tag/v2.0.21
Source code https://github.com/JetBrains/kotlin/tree/v2.0.21
Documentation https://kotlinlang.org/docs/home.html
Kotlin 2.0 Releases View full list

What Is New in Kotlin 2.0

Kotlin 2.0 is a major release centered on the stable K2 compiler, which brings significant improvements across the board. This update enhances performance, unifies Kotlin's platforms, and introduces new language features. The changes are designed to make development faster and more consistent.

Category Key Changes
Compiler Stable K2 compiler, improved build speed, new compiler plugins API.
Language & Syntax Stable context receivers, new ..< operator for open ranges, lifted vararg restrictions.
Tooling Kotlin IDE now powered by K2, smarter code completion, more reliable refactoring.
Standard Library Stable duration API, new functions for collections and math operations.
Multiplatform Gradle DSL simplification, default source set hierarchy, improved compilation.
Deprecations & Breaking Changes Removal of old compiler, deprecation of some experimental APIs, standard library adjustments.

How does the new K2 compiler improve my workflow?

The K2 compiler, now stable in Kotlin 2.0, is a complete rewrite that makes your builds noticeably faster. In practice, you'll see up to two times faster build times in clean builds for multi-module projects. This speed boost comes from smarter analysis and parallel processing of sources.

Beyond raw speed, the new compiler architecture provides a solid foundation for future language features. It fixes numerous long-standing issues in the old compiler, leading to more predictable and correct behavior. This means fewer "red code" false positives in the IDE and more reliable refactoring tools.

What new language features can I use today?

Context receivers are now stable, allowing functions to require multiple receiver types. This is powerful for designing fluent DSLs or operations that need access to several scoped contexts. You can declare a function with context(Path, Logger) to have both available in its body.

The new open range operator, ..<, lets you express ranges that exclude the end value, like 1 ..< 5 for 1,2,3,4. This fills a gap in the syntax, making intent clearer than using until. Also, vararg parameters can now be declared as nullable (vararg names: String?), offering more flexibility.

How is Kotlin Multiplatform development simplified?

Setting up a Kotlin Multiplatform (KMP) project is now more straightforward. The default source set hierarchy is enabled automatically, so common code is shared intuitively with platform-specific implementations. You no longer need verbose manual declarations in your build.gradle.kts for basic setups.

The Gradle DSL has been cleaned up, removing legacy configurations like withJava() and deprecated dependency declarations. Compilation for KMP projects is also faster and more consistent with the new K2 compiler. This matters because it reduces the initial friction and maintenance overhead for cross-platform projects.

What updates come to the Kotlin Standard Library?

The kotlin.time duration API is now stable, providing a type-safe way to work with time units. You can use 5.minutes or Duration.milliseconds(100) in calculations without ambiguity. The library also introduces new utility functions like replaceEach for strings and collections.

Math operations see additions like divmod that return both quotient and remainder. Some older, less consistent functions have been deprecated in favor of these new, clearer APIs. This cleanup helps keep the standard library focused and modern.

How does the IDE experience get better?

The IntelliJ IDEA Kotlin plugin now uses the K2 compiler for IDE features, leading to smarter and more responsive tooling. Code completion is faster and more accurate, especially for complex generic types or in multi-platform common code. You'll get relevant suggestions where the old engine sometimes stalled.

Refactoring operations like renaming or changing function signatures are more reliable and understand your code's structure better. This upgrade is a foundational shift that makes daily coding in Kotlin smoother and less interrupted by tooling glitches.

FAQ

Is Kotlin 2.0 source and binary compatible with Kotlin 1.x?
Yes, Kotlin 2.0 maintains source and binary compatibility with Kotlin 1.9. Your existing code should compile without changes, and libraries compiled with 1.x are usable with 2.0. The standard library has some cleanups but they are managed through deprecation cycles.

Do I need to upgrade my Gradle or Android project setup?
For most projects, updating the Kotlin Gradle plugin version to 2.0.0 is sufficient. However, due to the K2 compiler, some older compiler plugins or custom build scripts might need adjustment. Android projects can upgrade directly, but test thoroughly as the new compiler may catch previously ignored errors.

What happens to the old compiler?
The old compiler is removed in Kotlin 2.0. The K2 compiler is now the only option. This unification ensures everyone benefits from the performance and correctness improvements. Any workarounds for bugs in the old compiler are no longer necessary.

Are context receivers ready for production use?
Yes, context receivers are now a stable language feature in Kotlin 2.0. You can start using them in your production code without opt-in annotations. They are particularly useful for creating layered DSLs or injecting multiple dependencies into a function scope.

How do I migrate my Kotlin Multiplatform project to the new DSL?
The migration is often automatic or requires minimal changes. The Gradle plugin will apply the default hierarchy. You should remove deprecated DSL blocks like withJava() and update dependency declarations to use the new libs.versions.toml format or the updated implementation("group:name") style. Refer to the official migration guide for details.

Releases In Branch 2.0

Version Release date
2.0.21 1 year ago
(October 10, 2024)
2.0.21-RC 1 year ago
(October 01, 2024)
2.0.20 1 year ago
(August 22, 2024)
2.0.20-RC2 1 year ago
(August 13, 2024)
2.0.10 1 year ago
(August 06, 2024)
2.0.20-RC 1 year ago
(July 30, 2024)
2.0.10-RC2 1 year ago
(July 29, 2024)
2.0.10-RC 1 year ago
(July 11, 2024)
2.0.20-Beta2 1 year ago
(July 10, 2024)
2.0.20-Beta1 1 year ago
(June 18, 2024)
2.0.0 1 year ago
(May 21, 2024)
2.0.0-RC3 1 year ago
(May 10, 2024)
2.0.0-RC2 1 year ago
(April 29, 2024)
2.0.0-RC1 2 years ago
(April 09, 2024)
2.0.0-Beta5 2 years ago
(March 20, 2024)
2.0.0-Beta4 2 years ago
(February 13, 2024)
2.0.0-Beta3 2 years ago
(January 18, 2024)
2.0.0-Beta2 2 years ago
(December 15, 2023)
2.0.0-Beta1 2 years ago
(November 15, 2023)