For MPP library packaging and distribution, what w...
# multiplatform
p
For MPP library packaging and distribution, what will that look like? Seems like a few scenarios: 1) pure kotlin source(no target deps, no actual implementations) which is imported in the common sourceSet. (kolin-stdlib may be example?) 2) Libraries that contain expect and actual implementations. These require an artifact for common and each platform. Looks like all of these can be host with maven/jcenter/etc. Curious, does the kotlin compile to native with a jar file? does the compiler take class files and then transform them into IR before compiling into native? Any good reads or documentation around this? For scenario #1 can we simply publish a jar to maven in the typical way without any target deps and have that work in a MPP project?
h
For scenario #1 can we simply publish a jar to maven in the typical way without any target deps and have that work in a MPP project?
No, it's not possible at the moment. The Kotlin platform binary compiler implementations require their dependencies to be available in the same binary format, e.g. JVM class files for Kotlin/JVM, JS code for Kotlin/JS. So publishing even a library that shares all of its sources between all platforms requires all of the platform artifacts to be published as well (which implies that the library author must define the set of platforms to target).
The
kotlin-multiplatform
plugins already supports publishing with
maven-publish
out-of-the-box, so that all of the platform implementations are published together. With Gradle module metadata enabled (experimental feature, see http://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#experimental-metadata-publishing-mode), this will work for consumers as if it's a single publication.
Curious, does the kotlin compile to native with a jar file?
The Kotlin/Native libraries are packed into
*.klib
files. Those are basically ZIP archives, too, but their structure is different from that of conventional JARs.
does the compiler take class files and then transform them into IR before compiling into native?
No, it does not do that. Kotlin/Native compiles the sources directly into
*.klib
and/or native binaries.
p
Thank you for the thorough answer!