Multi-platform module recipes

I am very interested in multi-platform modules, but have not been able to find a lot of documentation. So I made a test project showing how you can build a multi-platform module, and what implementation options there are for classes that need both common and multi-platform code: GitHub - jstuyts/kotlin-multiplatform-recipes: Recipes for building multi-platform Kotlin modules.

Notes:

  • I used the stable Kotlin and plug-in version.
  • I cannot get extension functions for header types (only an interface is tested) to work in Java.
  • IntelliJ IDEA is very broken:
    • Lots of error messages.
    • Cannot run the Java app from the IDE.
  • Multi-platform module syntax is still subject to change, so don’t invest too much time in them yet.

Hopefully this will help some people with implementing multi-platform modules.

2 Likes

Great! That’s a quite extensive example covering many of the multiplatform language features. We probably could use it as a test site.

Note that the multiplatform tooling is being actively developed, so you might get more smooth experience with the recent fixes published in eap builds of the plugin, or even in the latest development build of the plugin. The corresponding gradle plugin and the standard library for the latter build are published to this bintray repository: JFrog Distribution: Get your software to where it needs to be -- ASAP!

Could you create a branch where that fails and report it to our issue tracker?

Probably you should delegate IDE build/run actions to gradle for your project. There is corresponding setting in Build Tools → Gradle → Runner group in settings.

Unless changed since I tried it couple months ago this will disable “Run/Debug current file” IDE functionality. So not a fix.

Here it is, but I could not add the multiplatform tag myself: https://youtrack.jetbrains.com/issue/KT-18257

Yes, that works.

I updated the documentation to include the information you provide above. And I added recipes for Java and JavaScript unit tests.

Two questions:

  1. Any idea when IntelliJ will support the header and impl keywords?
  2. Any docs for this?

Please note that this is a discussion about an unreleased feature. We’ll provide documentation and full IDE support when the feature is released.

That the feature is unreleased and unfinished shows, but I have converted one of my libraries and are satisfied with the possibilities and stability. I am using the stable releases of Kotlin (1.1.3-2), and I have not encountered issues with a successfully built JAR at run time yet. Here you can see which capabilities I used: https://github.com/squins/ooverkommelig/tree/multi-platform