On the road to Kotlin 1.2

Kotlin 1.2.30 adds new declaration in the standard library and more

Gabriela Motroc

© Shutterstock / Michael.P

Kotlin 1.2.30 is a new bugfix and tooling update for Kotlin 1.2. Let’s take a look at what’s in this update.

Kotlin 1.2.30 is here.

According to the blog post announcing the bugfix and tooling update, Kotlin 1.2.30 adds a new declaration in the standard library, which imitates the suspend modifier for lambda expression and there’s also support for TestNG inkotlin.test.

The new update brings support for Android modules in multiplatform projects and introduces a new feature in kapt for reporting annotation processing errors along with proper links to the original Kotlin declarations. Bugs in the compiler and IntelliJ plugin have been fixed and plenty of new inspections and intentions have been added to the IntelliJ plugin.

Kotlin 1.2.30 is compatible with all versions of IntelliJ IDEA from 2017.1 until 2017.3 and 2018.1 EAP, as well as with Android Studio 3.0.

Kotlin 1.2.30 highlights

Library changes

As we mentioned above, Kotlin 1.2.30 adds a new function to the Kotlin standard library with the following signature:

public inline fun <R> suspend(
    noinline block: suspend () -> R
): suspend () -> R = block

This function wraps a function literal into a value of a suspending function type and enables its usage as a suspending function.

Keep in mind that a suspend modifier for lambda expressions will be gradually introduced in the future Kotlin versions, and adding this function is the first step.

Thanks to Valeriy Zhirnov, another notable change is the support for the TestNG framework in kotlin.test. The new artifact kotlin-test-testng provides an implementation of Asserter on top of TestNG and maps the test annotations from kotlin-test-annotations-common to the TestNG test annotations.

Platform modules targeting Android

The update of the experimental multiplatform projects feature introduces support for Android platform modules. These modules should apply the corresponding plugin in the Gradle build script and can use the shared code from a common module:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-platform-android'
// ...

dependencies {
    expectedBy project(":multiplatform-app")
    // ...

Kapt diagnostic locations

As of now, kapt, the Kotlin annotation processing tool, can offer links to locations in the original Kotlin code rather than generated Java stubs as it reports errors encountered during annotation processing. You can enable this feature by adding these lines to the Gradle build script (build.gradle):

kapt {
    mapDiagnosticLocations = true

IntelliJ IDEA plugin improvements

Kotlin 1.2.30 brings various improvements in the IntelliJ IDEA Kotlin plugin, including performance improvements, bug fixes, and new inspections and intentions. Furthermore, you can now paste Kotlin code into a package item in the Project View, creating a new Kotlin file for the code:

You can find the complete list of changes in the changelog.


Update January 17, 2018

Kotlin 1.2.20 is here. This bugfix and tooling update for Kotlin 1.2 is compatible with all versions of IntelliJ IDEA from 2017.1 until 2017.3, and also with Android Studio 3.0 and 3.1 Canary.

Dmitry Jemerov, Principal Engineer at JetBrains wrote in the blog post announcing the update that it:

  • Adds support for Gradle build cache
  • Improves incremental compilation for Android and mixed Kotlin/Java projects
  • Provides IDE support for the new Kotlin style guide
  • Adds inlay hints in the editor for implicit parameters and receivers of lambdas, as well as values returned from lambdas
  • Supports development mode in JavaScript DCE Gradle task
  • Introduces new inspections, performance improvements and bug fixes in the IntelliJ plugin

Check out the changelog if you’re interested in the complete list of changes.

SEE ALSO: Kotlin 1.2: Multiplatform projects across the JVM and JavaScript

Compilation performance improvements

In this update, most of the improvements are related to the Gradle plugin. Speaking of, one of the improvements is the support for Gradle build cache.

If you’re using Gradle 4.3 or newer and the build cache is enabled (it’s not by default, requires --build-cache or org.gradle.caching=true), the plugin will reuse compilation results from previous executions of the Kotlin compile task, Jemerov explained.

As mentioned above, “build caching for Kotlin annotation processors is disabled by default because the dependencies of annotation processors cannot be tracked precisely by Gradle, so it may incorrectly reuse results of a previous execution of an annotation processor.”

If you want to enable it anyway, all you need to do is add these lines to the build script:

`kapt {
    useBuildCache = true

Another improvement is more precise tracking of changes in Java files, which allows you to avoid Kotlin recompilation when the changes in Java do not affect Kotlin code.

Keep in mind that this feature is experimental, so you’ll have to add this line to your gradle.properties file if you want to enable it:


Last but not least, changes to Android layout XML files no longer cause recompilation of all Kotlin sources. As of now, only Kotlin files that reference properties generated by Kotlin Android Extensions (kotlinx.android.synthetic.*) are recompiled.

The formatter fully supports the new Kotlin style guide

new official Kotlin style guide was recently released, covering the formatting of Kotlin code and the idiomatic use of language and library features. As of now, the formatter fully supports the new style guide. Plus, IntelliJ IDEA inspections can detect (and correct with quick fixes) many style guide violations can be detected.

Keep in mind that the formatting suggested by the new style guide is different from the default formatting previously used by the Kotlin plugin so you’ll have to apply the new guide explicitly in order to avoid unwanted formatting changes. To do that, go to Settings | Editor | Code Style | Kotlin and use the “Set from…” link to choose the code style.

JavaScript DCE development mode

The JavaScript dead code elimination (DCE) plugin will come in handy if you need to reduce the output size of the Kotlin to JavaScript compiler. The DCE process takes a bit of extra time, Jemerov warned, and the output size doesn’t matter during development, so you can now disable dead code elimination.

In order to do that, you’ll have to use the following option:

runDceKotlinJs.dceOptions.devMode = true 

Check out Dmitry Jemerov’s blog post for the complete list of highlights.

Gabriela Motroc
Gabriela Motroc is editor of JAXenter.com and JAX Magazine. Before working at S&S Media she studied International Communication Management at The Hague University of Applied Sciences.

Leave a Reply

Be the First to Comment!

Notify of