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-multiplatform Gradle 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: GitHub - h0tk3y/k-new-mpp-samples: Samples for the new multiplatform projects prototype. 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.
Does this use the maven-publish Gradle plugin? How is the javadoc JAR handled by default in the case, like with Sonatype, where release to Maven central fails without it? I’ve had to do what I’ve seen other Kotlin projects do and make an empty one manually. (can delete/redirect question if this announcement post is an unacceptable place to discuss this)
Yes, the default publishing configuration by the kotlin-multiplatform plugin is done with the maven-publish plugin (note: it is done only if you apply maven-publish), as it provides some features we need for publishing a multiplatform library as a connected set of artifacts/modules which can be consistently consumed by another multiplatform project, in contrast with the old maven plugin.
We do not create the Javadoc JAR by default, though, but when you need it you will be able to add it to the publication with the maven-publish plugin API, i.e. with the publishing { publications { ... } } DSL.
However, we are going to provide a default setup for the sources JARs for each target. This and some more changes in multiplatform libraries publishing are in-progress now.
Does this mean IDEA will soon have full support for Kotlin native? I feel that with a decent set of gir bindings Kotlin would be a great language for developing with GTK/GNOME etc sine Vala is slowly dying. But having to either make apps run on the JVM or pay for a decent IDE for native is a put-off.
You may have preconfigured source sets, as well as custom ones, and all of them will turn into IDE modules during the IDE import. In terms of modules, there will be a separate IDE module for common code with expect declarations, e.g. commonMain, and a different one for a platform realization, e.g. jvm6Main. You may take a look at the simplest web template with such a structure by creating a new Multiplatform (Web) project via New Project Wizard in Intellij IDEA, Kotlin section, having 1.3-M2 Kotlin plugin installed.
Moreover, platform-specific source sets may share actual declarations as it’s done in one of the provided examples.
I found the KotlinNativeTarget enum by reviewing the code that’s why we should have a sample app or document this in the great k-new-mpp-sample which is really helpful.
@juanchosaravia Thanks for the note about iOS frameworks, I’ve added it to the Notes on Kotlin/Native support section of k-new-mpp-samples. We are going to provide a sample project targeting iOS sometime soon as well.
Looks really good. Does this now also mean that I can (easily, on class by class basis) have some classes have different code for android, js and jvm and some share code between android and jvm (but not js). Is that also possible if the android variant is in reality a java library that is just designed for use on Android.