Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

IntelliJ IDEA 2017.3: Support for Kotlin Multi-Platform Projects

DZone's Guide to

IntelliJ IDEA 2017.3: Support for Kotlin Multi-Platform Projects

The IntelliJ IDEA Kotlin plugin just got an update! Check out how it supports multi-platform projects and some helpful tips to get you started.

· Java Zone
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

The Kotlin plugin bundled with IntelliJ IDEA 2017.3 has been updated to Kotlin 1.2. The key new feature of Kotlin 1.2 is its support for multi-platform projects – projects where the same code is compiled to target the JVM or JavaScript. Such projects consist of common modules, containing platform-independent code, and platform-specific modules. To support calling the platform-specific APIs from common code, the common code can specify expected declarations, and then platform-specific modules need to provide the actual declarations. The IDE now supports creating and running multi-platform projects, as well as code editing and navigation assistance for expected and actual declarations.

Template Multi-platform Project

First of all, now it is possible to create a template project to start exploring the new Multi-platform projects feature.

image3

The IDE will generate a multi-platform project with the following modules: a common module for the shared code between the platforms, and two platform-specific modules, one for JVM and another for JavaScript.

image2

Please keep in mind that multi-platform projects should be built with Gradle.

When you compile a project such as this for a specific platform, IntelliJ IDEA generates the code for both the common and platform-specific parts.

Detecting Expected Declarations Without the Corresponding Actual Declarations

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

Expected declarations should have actual declarations in the platform-specific module.
IntelliJ IDEA 2017.3 will detect and alert you if you try to use an expected declaration without the corresponding actual declarations.

image4

Intention Action to Create the Actual Class

For missing declarations for JS and JVM platforms, the Kotlin plugin provides an intention action to create actual declarations.

image1

Navigation Between Expected and Actual Declarations

The IDE provides a gutter icon which lets you easily navigate between expected and actual declarations.

You’re welcome to share your feedback here in the comments or on Twitter. If you encounter any bugs, please don’t forget to report them directly to the issue tracker. Thanks!

Happy developing!

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

Topics:
java ,intellij idea 2017.3 ,kotlin

Published at DZone with permission of Zlata Kalyuzhnaya, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}