Kotlin 1.7.0 Debuts K2 Compiler Alpha and Enhanced Incremental Compilation for Gradle
JetBrains has unveiled Kotlin 1.7.0, marking a significant advancement for the Kotlin programming language. This release introduces the alpha version of the K2 compiler, a major step forward intended to enhance performance, streamline the development of new language features, and unify Kotlin’s support across various platforms. While the K2 compiler is still in its early stages, it currently supports only JVM projects, with limited compatibility for compiler plugins—only the kapt plugin for annotation processors is functional at this time.
Alongside the K2 compiler, Kotlin 1.7.0 brings a fresh approach to incremental compilation within Gradle, a build automation tool commonly used in Android development. The new version enhances support for incremental compilation by allowing changes within dependent modules to trigger recompilation only where necessary. This improvement also includes better support for compilation avoidance, which helps speed up the build process. Future updates are expected to stabilize this technology and extend support to other backends, such as JavaScript.
The Kotlin 1.7.0 release also features several other noteworthy enhancements. Non-nullable types have been promoted to stable status, improving interoperability when extending generic Java classes and interfaces. Builder inference, which helps when calling generic builder functions, is now automatically activated in cases where regular type inference falls short. Additionally, opt-in requirements have been stabilized, reducing the need for extra compiler configuration.
In addition to improving performance, K2 is intended to speed up development of new language features, unify platforms Kotlin supports, and provide an API for compiler extensions. The alpha version, however, only works with JVM projects. And no compiler plugins except the kapt plugin for annotation processors work with it yet.
Kotlin 1.7.0, introduced June 8, also offers a new approach to incremental compilation in the Gradle build automation tool, with compilation now supported for changes made inside dependent modules. Support for compilation avoidance also has been improved. Gradle, like Kotlin, is leveraged in the development of Android mobile applications. Plans call for stabilizing the compilation technology and adding support for other back ends, such as JavaScript.
Another significant improvement is the introduction of an underscore operator for type arguments, which aids in automatically inferring the type of an argument when other types are specified. Kotlin 1.7.0 also enables implementation by delegation to an inlined value of an inline class, allowing developers to create lightweight wrappers that minimize memory allocation.
This release follows a beta version of Kotlin 1.7.0 published in May, and it builds upon the improvements introduced in Kotlin 1.6.20, which arrived in April. For those eager to dive into these new features, instructions and resources are available on the official Kotlin website.