It’s here! It's here!

Kotlin 1.2: Multiplatform projects across the JVM and JavaScript

Jane Elizabeth
Kotlin 1.2
© Shutterstock / SewCream

The next big release from Kotlin is here! Kotlin 1.2 is a major step forward with a bunch of cool new features, including code-sharing between platforms. Let’s take a look at what’s in this new release.

The next major Kotlin release has arrived! This is a major step forward for Kotlin 1.2, which boasts operability across platforms as well as improved compilation times and library improvements. This time around, the key word is compatibility.

Previously in the Kotlin 1.1 release, it was possible to compile Kotlin code to JavaScript and run it in your browser. Now, in Kotlin 1.2, you can reuse code between the JVM and JavaScript. This means you can write the business logic ones and reuse the code across all tiers of your application from backend to browser frontend, and even the Android mobile app.

Let’s take a closer look at what’s in this latest version.

Multiplatform projects

Kotlin 1.2 is designed for multiplatform projects. This allows you to build a whole application – backend, frontend, and Android mobile app – with just one codebase. Target platforms include the JVM and JavaScript, with Native to follow.

Kotlin 1.2

A multiplatform project consists of three types of modules:

  • A common module contains code that is not specific to any platform, as well as declarations without implementation of platform-dependent APIs. Those declarations allow common code to depend on platform-specific implementations.
  • A platform module contains implementations of platform-dependent declarations in the common module for a specific platform, as well as other platform-dependent code. A platform module is always an implementation of a single common module.
  • A regular module that targets a specific platform. It can either be dependencies of platform modules or depend on platform modules.

To call platform-specific code from a common module, you can specify expected declarations – declarations for which all platform-specific modules need to provide actual implementations.

This feature also includes extra library support to move more logic to the common code.

  • kotlin.test, included out of the box in Kotlin 1.2, lets you write your test once and run it under both the JVM and JS;
  • kotlin.html supports isomorphic rendering – using the same code to render HTML in the backend and in the frontend;
  • kotlinx.serialization allows you to easily marshal Kotlin objects between different tiers of your application, using JSON or ProtoBuf as serialization formats.

While this is an experimental feature for Kotlin 1.2, it’s an exciting one to see where it may go. Check out the documentation for more information.

SEE MORE: Kotlin Native serverless tutorial: Fun with Fibonacci

Improved compilation speed

It’s not a major update without improving the speed. While developing 1.2, the Kotlin team tried to make the compilation process faster. They managed to achieve an impressive 25% improvement over Kotlin 1.1, with room for growth in future 1.2.x updates.

Kotlin 1.2

Other improvements

Kotlin 1.2 also boasts a number of other small improvements to the language and standard libraries.

  • Backwards compatibility across Kotlin 1.0 and 1.2.
  • A more concise syntax for passing multiple arguments to an annotation (array literals)
  • Support for the lateinit modifier on top-level properties and local variables, as well as checking whether a lateinit variable is initialized
  • Smarter smart casts and improved type inference in certain cases;
  • Compatibility of the standard library with the split package restrictions introduced in Java 9;
  • New kotlin.math package in the standard library
  • New standard library functions for working with sequences and collections, including a set of functions for breaking a collection or sequence into potentially overlapping groups of a fixed size.

More new features can be found here.

SEE MORE: Kotlin 1.2 Beta2 adds missing pieces to multiplatform project narrative

How to get Kotlin 1.2

You can try Kotlin online here.

  • In Maven, Gradle and npm: Use 1.2.0 as the version number for the compiler and the standard library. See the docs here.
  • In IntelliJ IDEA: 2017.3 has Kotlin 1.2 bundled, in earlier versions Install or update the Kotlin plugin to version 1.2.
  • In Android Studio: Install or update the plugin through Plugin Manager.
  • In Eclipse: install the plugin using Marketplace.
  • The command-line compiler can be downloaded from the Github release page.


Jane Elizabeth
Jane Elizabeth is an assistant editor for

comments powered by Disqus