Multi-platform module recipes


#1

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: https://github.com/jstuyts/kotlin-multiplatform-recipes

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

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: https://bintray.com/kotlin/kotlin-dev/kotlin


#3

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.


#4

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


#5

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.


#6

Two questions:

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

#7

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


#8

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