In Kotlin 1.3, we kept up active development and improvement of the multiplatform story. Aiming to simplify the projects structure, make code sharing more granular, and extend the platforms list by adding Kotlin/Native, we arrived at the new multiplatform projects model, which brings all of this along with other new features.
The recently released Kotlin 1.3-M2 already contains the very early access preview of the new model:
- the new
kotlin-multiplatformGradle plugin enables setting up all target platforms in a single Gradle subproject;
- Kotlin/Native targets now share the DSL and can co-exist in the same project with JVM and JS ones;
- with many provided configuration presets, the notion of a target platform becomes more flexible; for example, you may define JVM, NodeJS, and Linux targets each with a single line;
- now it is possible to share a part of code between only some of the targeted platforms rather than all of them (for instance, there can be one part for JVM, JS, and Native and another piece shared only between JVM and JS in the same project);
- publishing MPP libraries is available out-of-the-box;
- dependency management gets simpler: a single line in the build script is enough to use a multiplatform library across all of the target platforms;
To find out more, follow this link: https://github.com/h0tk3y/k-new-mpp-samples. The repo contains a detailed description of the new model and several project examples which demonstrate some of the advantages listed above, such as partial code sharing in the
split-actuals project. Alternatively, you may create a new multiplatform project through New Project Wizard in IntelliJ IDEA: there is a new project template at the
Kotlin tab, called
Kotlin (Multiplatform - Web) , with JVM and JS targets specified. There’s more to come!
While it already works in many use cases, there is still a lot to improve in the tooling and IDE support. Building multiplatform projects based on the new model from within IntelliJ IDEA and importing them into Android Studio are not supported yet, as well as writing the build scripts with Gradle Kotlin DSL. You may find all the known issues with this search query: https://youtrack.jetbrains.com/issues/KT?q=%23new-multiplatform.
Nevertheless, we encourage you to try the new multiplatform projects and let us know what you think. Your feedback is more than welcome, as well as YouTrack issues for bugs you may encounter
Feel free to ask any questions here and let us know if you experience any difficulties.