Kotlin 1.2 Released: Sharing Code between Platforms


Members of our community have translated
this blog post into several languages:

Today we’re releasing Kotlin 1.2. This is a major new release and a big step on our road towards enabling the use of Kotlin across all components of a modern application.

In Kotlin 1.1, we officially released the JavaScript target, allowing you to compile Kotlin code to JS and to run it in your browser. In Kotlin 1.2, we’re adding the possibility to reuse code between the JVM and JavaScript. Now you can write the business logic of your application once, and reuse it across all tiers of your application – the backend, the browser frontend and the Android mobile app. We’re also working on libraries to help you reuse more of the code, such as a cross-platform serialization library.

Kotlin 1.2

Kotlin 1.2 is already bundled in IntelliJ IDEA 2017.3, which is being released this week. If you’re using Android Studio or an older version of IntelliJ IDEA, you can install the new version from the Tools | Kotlin | Configure Kotlin Plugin Updates dialog.

This release includes a lot of work done by external contributors, and we’d like to thank everyone who sent us feedback, reported issues, and especially those who submitted pull requests.

Multiplatform Projects

A multiplatform project allows you to build multiple tiers of your application – backend, frontend and Android app – from the same codebase. Such a project contains both common modules, which contain platform-independent code, as well as platform-specific modules, which contain code for a specific platform (JVM or JS) and can use platform-specific libraries. 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.

MPP

For more information on the feature, please check out the documentation.

As mentioned previously, we’re also working on a set of common libraries to allow you to move more of the logic to 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;
  • kotlinx.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.

Note that multiplatform projects are currently an experimental feature; it means that the feature is ready for use, but we may need to change the design in the subsequent release (and if we do, we’ll provide migration tools for existing code).

Compilation Performance

Over the course of development of 1.2, we’ve put a lot of effort in making the compilation process faster. We’ve already reached approximately 25% improvement over Kotlin 1.1, and we see significant potential for further improvements, which will be released in 1.2.x updates.

The graph below shows the difference in compilation times for two large JetBrains projects built with Kotlin:
CompilationSpeed

Other Language and Library Improvements

We’ve also made a number of smaller improvements to the language and the standard library:

  • 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.

For more information and code examples, please see the What’s New in Kotlin 1.2 documentation page.

Kotlin Around the World

Since the release of Kotlin 1.1 in March of this year, Kotlin has made huge gains in adoption all around the world. The culmination of that was KotlinConf, our first worldwide conference, with around 1200 attendees gathering in San Francisco on November 2-3rd. We’ve recorded all the talks, and the videos are now available.

Kotlin is now an officially supported language for Android development, with out-of-the-box support in Android Studio 3.0, as well as official samples and style guides published by Google. As a result, Kotlin is already used in more than 17% of projects in Android Studio 3.0, including many apps from the hottest startups as well as Fortune 500 companies.

Users

On the server side, Spring Framework 5.0 has been released with many Kotlin support features, and vert.x has been supporting Kotlin since their 3.4.0 release. Also, Gradle now comes with support for Kotlin DSL out of the box, and the Gradle Kotlin DSL project is rapidly approaching the 1.0 release.

The number of lines of open-source Kotlin code on GitHub has now exceeded 25 million. And on Stack Overflow, Kotlin is both one of the fastest-growing and one of the least-disliked languages.

KotlinAdoption

The community growing around Kotlin is also really amazing. There are over 100 user groups all around the world, and so many talks that we have a hard time keeping track of all of them – but for those that we do know about, the talks map gives you a very good idea of how wide-spread the use of Kotlin really is.

KUGmap

And for those who’re just starting to learn Kotlin, there’s an ever-growing number of books (including our own “Kotlin in Action”, now available in English, Russian, Japanese, Chinese and Portuguese), online courses, tutorials and other resources.

Meet the Team: Webinar and Reddit AMA

To share with you more information on the new release, we plan to host a webinar on multiplatform projects with Kotlin 1.2 on December 7th, 18:00 CET. Please register; space is limited!

The Kotlin team will also conduct an AMA (Ask Me Anything) on the Kotlin Reddit on December 5th. We’ll start at noon CET, and we’ll be there with you for the next 24 hours.

How to Upgrade

As always, you can try Kotlin online at try.kotlinlang.org.

  • 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.

Compatibility. In Kotlin 1.2 the language and the standard library are backwards compatible (modulo bugs): if something compiled and ran in 1.0 or 1.1, it will keep working in 1.2. To aid big teams that update gradually, we provide a compiler switch that disables new features. Here is a document covering possible pitfalls.

Have a nice Kotlin!

This entry was posted in Releases and tagged . Bookmark the permalink.

40 Responses to Kotlin 1.2 Released: Sharing Code between Platforms

  1. Is the Multiplatform Projects initiative competing with Xamarin and React Native? I’m trying to decide which platform to study right now.

    • Dmitry Jemerov says:

      This depends on when you want to have results. Sharing Kotlin code between Android and iOS is not quite there yet; it’ll take some more time for us to build the missing pieces. Also, our approach is focused on sharing only business logic between platforms, not UI code. If you want to share UI between platforms, you should look into other technologies.

      • Antoni Mysliborski says:

        Would it be possible to write using React Native but with Kotlin instead of JavaScript?

        • Dmitry Jemerov says:

          It is possible now, but React Native is not the technology stack that we’re currently focusing on supporting.

          • Antoni Mysliborski says:

            Do you know about anyone who managed it? I tried to search for some examples but couldn’t find any. Given the rising popularity of RN it would be nice to be able to use it with some saner language than JS :)

            • Dmitry Jemerov says:

              A team at JetBrains did that, but as far as I know they never published any code (and the code they had wasn’t really production quality).

    • yeradis says:

      Check Flutter.io

  2. Sroka says:

    Great work guys! I have question regarding availability of coroutines in JS target. Is it already there?

  3. Даниил Водопьян says:

    Mutating the backing field of a read-only property by assigning field = … in the custom getter has been deprecated

    Was it done for a technical reason, or just to prevent terrible code?

  4. David Scrève says:

    Why kotlin is not available in WebStorm while kotlin native is shipped with CLion ?

    • Dmitry Jemerov says:

      We plan to build a WebStorm version of the Kotlin plugin similarly to the way the CLion plugin was done; it’s simply not implemented yet.

  5. Werner Punz says:

    Btw. is there any reason why you guys compile against a huge kotlin.js runtime library in your javascript compile target. Even for things which javascript perfectly fine can handle itself (like classes, inheritance etc…)
    I wanted to use kotlin as high level frontend for a js library but the kotlin.js dependency basically prevented that, oh well back to typescript then.

    • Dmitry Jemerov says:

      There is much more than one possible set of semantics for classes; both C++ and Java have classes, but they look completely different. In the same way, Kotlin/JS needs to support the Kotlin semantics for classes, and not whatever is supported by JS.

      We’ve also built a dead code elimination tool that greatly reduces the size of the standard library dependency in most projects.

        • Werner Punz says:

          You do not have to go to Scala for examples here.
          Typescript is the perfectly fine example with its approach of it must be compilable into pure ecmascript on all supported language levels.

          class bla {

          is compiled against real javascript classes in es6 and higher
          and against prototype inheritance in lower dialects of es.
          Heck if pure es classes do not do it you always can fall to prototypes which are one level deeper.

          But that is just an example. The problem simply is that every compilation relies on a runtime file which is a no go for third party libraries. Kotlin itself is a nice language however and it might be a viable option for many js projects, just not for mine.

  6. Jan Vladimir Mostert says:

    This is great news, well done!!

  7. Melanie Myers says:

    I just updated today.

    When I create a new Kotlin file in my Kotlin project, it opens as .kt file but Intellij treats it as a regular text file (no auto-complete of main, etc.).

    However, when I create a new Kotlin class, it opens as a .kt file but treats it as an actual Kotlin file. This is true even after I delete the class declaration in the new file.

    Is this a bug or a part of the new design?

    Thx

    • Dmitry Jemerov says:

      This is an IntelliJ issue. To fix it, please open Settings | Editor | File Types, select “Text” in the list and make sure that there are no Kotlin-related file names in the “Registered Patterns” list.

  8. HI! I can’t update plugin in Android Studio 3.0.1 from latest stable (1.1.61), it tells me “Plugin not installed” where I can share log?

  9. Nhuy S Van says:

    I like Java but, man, Kotlin will take its place on the chart in no time. I love Kotlin. Thank you for creating such an awesome language. By the way, do you guys plan on having array, list and map literals like Groovy does?

  10. Uwe Aime Van says:

    Do you guys have plan to allow kotlin works along side of OIS platorm

  11. smallufo says:

    Can I depend my common code on Java’s libraries ? such as Optional / Stream / LocalDateTime ? Will they be translated to JS too ? Or it’s better make the common code as Kotlin as possible ?

    • Dmitry Jemerov says:

      No, common code can only depend on other common libraries. Kotlin has no support for translating Java bytecode into JS.

  12. xilin says:

    is there any chinese translation?

  13. ALEXANDER MINKIN says:

    Thanx guys for such good work. Kotlin spb one love

  14. Jakub Błaszczyk says:

    do you plan to enhance kotlin.test library with compiler-driven mock generation in spirit of Mockito? that would positively impact performance of CI pipelines out there :)
    how about AssertJ-inspired DSL? or Cucumber? do you have a clear roadmap for testing side of kotlin?

    • Dmitry Jemerov says:

      We have no plans to build a mock generation library for Kotlin at this time. For fluent assertions, there are quite a few third-party solutions, including hamkrest and kotlintest. Cucumber already works with Kotlin, as far as I understand; the only thing missing is IDE support, which we’ll likely add at some point.

  15. Samson Ajax says:

    I love Kotlin. I have chosen it as my language. Can i use Kotlin to develop Window application and probably to work on other platform too?

    • Dmitry Jemerov says:

      Yes, you can. The JVM runs on all modern desktop operating systems, so you can run Kotlin code under any OS.

  16. Sevil says:

    Such a great news – looking forward to try it with both iOS and Android when it is a little bit more mature. Android development hasn’t been so much fun for really long time for me. Thank you so much!

Leave a Reply to yeradis Cancel reply

Your email address will not be published. Required fields are marked *