What Is New in Kotlin 1.8
Kotlin 1.8 delivers updates across the compiler, language features, and libraries, focusing on performance and developer experience. The key highlights are summarized below.
| Area | Key Changes |
|---|---|
| Language & Compiler | Stable support for incremental compilation in JVM KAPT, experimental K2 compiler updates, and new language feature for recursive generic types. |
| Standard Library | New functions for working with durations, extended java.nio.file.Path API, and updates to the kotlin.random generator. |
| Tooling | Gradle version catalog support in the Kotlin Gradle plugin and updates to the kapt and Kotlin/JS plugins. |
| Platform Updates | Kotlin/JVM updates for JDK 19 compatibility and Kotlin/Native memory manager becoming stable. |
What language and compiler improvements are in Kotlin 1.8?
The compiler gets significant upgrades for faster builds and future-ready architecture. Incremental compilation for JVM KAPT is now stable, which cuts down rebuild times when using annotation processors. This matters because waiting for kapt was a common bottleneck in Android and other JVM projects.
The K2 compiler remains in alpha but sees progress, with support for more language constructs and the JS and Native targets. In practice, this is a foundational change for the entire Kotlin ecosystem, aiming for faster compilation and unified behavior across all platforms.
A subtle but powerful language change allows a class to implement Comparable<itself> directly. This simplifies defining comparison logic for generic types without workarounds.
How does the standard library get better in 1.8?
Kotlin 1.8 introduces a more expressive API for handling time durations. The kotlin.time package gets new factory functions like 5.seconds and extension properties for conversion, making time-based code more readable and less error-prone.
File I/O operations become more idiomatic with extension functions for java.nio.file.Path. You can now use Kotlin-style .extension or .nameWithoutExtension directly on a Path object, reducing boilerplate when interacting with Java's NIO API.
The kotlin.random generator is updated to ensure consistent randomness across different platforms for the same seed. This is crucial for logic that depends on reproducible random sequences, like in tests or game states.
What tooling updates should Gradle users know about?
The Kotlin Gradle plugin now supports Gradle's version catalogs (TOML files) for declaring dependencies. You can reference Kotlin dependencies directly from the catalog in your build.gradle.kts files, which helps centralize and manage versions.
Other plugin updates include the kapt plugin aligning its behavior with the stable incremental compilation and the Kotlin/JS plugin receiving improvements for IR-based backend configuration. These changes streamline the build process and reduce configuration complexity.
Are there updates for Kotlin/JVM and Kotlin/Native?
Kotlin/JVM is updated for compatibility with JDK 19. The standard library can now leverage new classes and methods from this JDK version, ensuring your Kotlin code works seamlessly on newer Java runtimes.
The big news for Kotlin/Native is the stabilization of the new memory manager. It eliminates the differences between the JVM and Native platforms regarding object lifecycle and concurrency, making it much easier to share code. In practice, you can write concurrent code for Native that feels like Kotlin on the JVM.
FAQ
Is the K2 compiler ready for production in Kotlin 1.8?
No, the K2 compiler is still in alpha for Kotlin/JVM, Kotlin/JS, and Kotlin/Native. It's available for experimental use only. The focus in 1.8 is on expanding its feature coverage and stability across all targets.
What is the main benefit of stable incremental compilation for kapt?
It significantly reduces build times in projects using annotation processors (like Dagger or Room). Only modules affected by changes are re-processed, not the entire project, leading to faster development cycles.
How does the new memory manager affect my existing Kotlin/Native code?
The new memory manager is now stable and enabled by default. It removes most restrictions on object sharing between threads, making concurrency patterns from Kotlin/JVM more applicable. Most code should work as before or require minimal adjustment.
Can I use the new duration APIs for Android development?
Yes, the new kotlin.time.Duration APIs are part of the standard library and work on Android. They provide a Kotlin-centric way to define and operate on time units, independent of the older java.time API levels.
Does the update to kotlin.random change how I seed my random number generator?
The underlying algorithm is updated for cross-platform consistency, but the public API remains the same. If you were using a fixed seed to get reproducible sequences, you can now rely on them being identical across JVM, JS, and Native, which wasn't guaranteed before.