Releases

Kotlin 1.5.30 Is Now Available!

Since Kotlin 1.5.30 is the last incremental release before Kotlin 1.6.0, it includes many experimental language and standard library features that we are planning to release in Kotlin 1.6.0. Give them a try and share your feedback with us, you can really influence the final result! These experimental features include sealed when statements, changes to opt-in requirements, instantiation of annotation classes, improvements to the Duration and Regex stdlib APIs, and more.

With Kotlin 1.5.30, you can also enjoy native support for Apple silicon, the promotion of the Kotlin/JS IR backend to Beta, the ability to use custom cinterop libraries in the shared native code of multiplatform applications, support for Java toolchains provided by the Kotlin Gradle plugin, and much more.

Update to Kotlin 1.5.30

This blog post provides an overview of the updates in this release:

  • Language improvements, including sealed when statements, support for suspend functions as supertypes, and changes to opt-in requirements.
  • Multiplatform improvements, including the ability to use custom cinterop libraries in shared native code and support for XCFrameworks as an output format.
  • Kotlin/JVM improvements, including instantiation of annotation classes and improved configuration of nullability annotation support.
  • Kotlin/Native improvements, including native support for Apple silicon and an improved Kotlin DSL for the CocoaPods Gradle plugin.
  • Kotlin/JS IR improvements, including the promotion of the JS IR backend to Beta and a better debugging experience for the new backend.
  • Gradle improvements, including support for Java toolchains and easier ways to explicitly set the Kotlin daemon’s JVM arguments.
  • Standard library improvements for the Duration and Regex APIs.

Automatically update to Kotlin 1.5.30

If you use IntelliJ IDEA or Android Studio, you have the option to automatically update to the new Kotlin release as soon as it becomes available.

Learn more about installing Kotlin 1.5.30.

Note: the latest version of IntelliJ IDEA – 2021.2 – doesn’t support Kotlin 1.5.30. If you have already upgraded, you can easily install IntelliJ IDEA 2021.1 using the JetBrains Toolbox App and use Kotlin 1.5.30 in that version, or you can wait for the Kotlin 1.5.31 bug-fix release.

Language

The Kotlin roadmap includes adding support for sealed when statements, releasing opt-in annotations, improving type inference, and stabilizing builder inference. 

Kotlin 1.5.30 takes a step down this road by providing a preview of these features, whose release is planned for 1.6.0.

Sealed when statements

Sealed when is a long awaited feature with more than 280 votes in YouTrack. If you enable this feature in 1.5.30, the Kotlin compiler will warn if one of your when statements is not exhaustive. This will make your code safer without you having to introduce your own functions.

Give this feature a try and provide your feedback in this YouTrack ticket

Support for suspend functions as supertypes

Kotlin 1.5.30 provides a preview of an ability to use suspend functional types as super interfaces, although it has some limitations. It’s one of the missing pieces in the Kotlin coroutines design.

Enable this feature, give it a try, and provide your feedback in this YouTrack ticket.

Changes to opt-in requirements

As a further step toward the release of opt-in annotations, Kotlin 1.5.30:

  • Presents new rules for using and declaring opt-in requirement annotations on different targets. 
  • Requires opt-in even for implicit usages of an experimental API. For example, if the function’s return type is marked as an experimental API element, a usage of the function requires you to opt-in even if the declaration is not marked as requiring an opt-in explicitly.

Try out the changes and share your feedback in this YouTrack ticket

Learn more about opt-in requirements

Improvements to type inference on recursive generic types 

With type inference on recursive generic types enabled, the Kotlin 1.5.30 compiler can infer a type argument based only on the upper bounds of the corresponding type parameter if it is a recursive generic. This makes it possible to create various patterns with recursive generic types that are often used in Java to make builder APIs.

Eliminating builder inference restrictions 

With eliminating builder inference restrictions enabled, Kotlin 1.5.30 removes a builder inference restriction. Not only can you specify the type information that builder inference can infer, but you can also use the get function on it. For example, you can call get() inside a lambda argument of buildList() without explicitly specified type arguments.

Kotlin Multiplatform

Kotlin 1.5.30 includes the following improvements for Kotlin Multiplatform:

  • Ability to use custom cinterop libraries in shared native code, which extends the ability to share platform-dependent libraries shipped with Kotlin/Native. 
  • Support for XCFrameworks as an output format for all Kotlin Multiplatform projects. XCFrameworks help gather logic for all the target platforms and architectures in a single bundle and don’t require removing unnecessary architectures before publishing the application to AppStore.
  • New default publishing setup for Android artifacts. This setup will be compatible with any build type (like debug or release)  by default. Before 1.5.30, the metadata generated by the maven-publish Gradle plugin when publishing a multiplatform library for Android included the build type attribute for every published Android variant. This made it compatible only with the same build type used by the library consumer. 

Kotlin/JVM

With Kotlin 1.5.30, Kotlin/JVM gets the following updates:

Kotlin/Native

Kotlin 1.5.30 provides the following improvements for Kotlin/Native:

Kotlin/JS

Kotlin 1.5.30 provides the following improvements for Kotlin/JS:

Gradle

Kotlin 1.5.30 introduces the following features to improve the Kotlin Gradle plugin user experience:

  • Support for Java toolchains. Gradle 6.7 introduced support for Java toolchains, which make it easy to select a JDK for project compilation. Just declare the version you need in the build script and Gradle does the rest, finding it on your host machine or even downloading and installing it if it’s not there yet. The Kotlin Gradle plugin supports Java toolchains for Kotlin/JVM compilation tasks. For Gradle versions 6.1-6.6, set a JDK home with the UsesKotlinJavaToolchain interface.
  • Easier ways to explicitly specify Kotlin daemon JVM arguments. If nothing is specified for the Kotlin daemon, it inherits arguments from the Gradle daemon. You can now also specify arguments for a specific task, as well as for the Kotlin extension, as a single line in build.gradle.kts or gradle.properties.

build.gradle.kts

gradle.properties

Standard library

Kotlin 1.5.30 brings improvements to the standard library’s Duration and Regex APIs:

Duration API improvements

As indicated in our libraries roadmap, we’re going to stabilize the Duration API in Kotlin 1.6.0, which means this is the last chance to give it a try and share your feedback with us on anything you’d like changed. We would appreciate your feedback in this KEEP.

Kotlin 1.5.30 provides a preview of API improvements. The output of Duration.toString() is now more readable. For example, Duration.minutes(920).toString() produces 15h 20m instead of the previous 920m.

A negative duration is now prefixed with a minus sign (-), and it is surrounded by parentheses if it consists of multiple components: -12m and -(1h 30m).

This release also provides a preview of new functions for parsing Duration from String:

  • parse() parses Duration objects from strings formatted as Duration’s toString() or from strings representing ISO 8601 durations (such as toIsoString() outputs).
  • parseIsoString() parses Duration objects from strings representing ISO 8601 durations.
  • *OrNull() counterparts for both functions.

Regex API improvements

Kotlin 1.5.30 provides new experimental functions for regular expressions:

  • matchesAt() checks whether a regex has a match in the specified position of a String.
  • matchAt() returns the match if one is found.
  • splitToSequence() is a lazy counterpart of split(). It splits the string around matches of the given regex, but returns the result as a Sequence. A similar function has also been added to CharSequence.

How to install Kotlin 1.5.30

If you already use IntelliJ IDEA or Android Studio, your IDE will suggest updating Kotlin to 1.5.30 automatically. You can also update manually by following these instructions

You can download the latest versions of these IDEs to get extensive support for Kotlin:

  • IntelliJ IDEA – for developing Kotlin applications for various platforms.
  • Android Studio –  for developing Android and cross-platform mobile applications.

Make sure that you have also updated the kotlinx libraries to compatible versions and specified version 1.5.30 of Kotlin in the build scripts of your existing projects.

If you need the command-line compiler, download it from the Github release page.

If you run into any problems

Stay up to date with information about the latest Kotlin features! Subscribe to receive Kotlin updates by filling out the form to the right of this post.

Read and watch more

External contributors 👏👏👏

We’d like to thank all of our external contributors whose pull requests were included in this release:

Jinseong Jeon, pyos, Tianyu Geng, Mark Punzalan, Mads Ager, Ivan Gavrilovic, Steven Schäfer, Vladimir Ivanov, Hung Nguyen, Matthew Gharrity, Jiaxiang Chen, Ivan Kochurkin, Iaroslav Postovalov, Toshiaki Kameyama, Udi Cohen, Xin Wang, bracadabra

Discover more