Compiling same Kotlin code to JVM and JS


#1

I’ve found this Compiling Kotlin to both Java and Javascript from the same module

but it is old and I can’t find any new info regarding compiling the same module to JVM and JS.

My main interest would be to create a validation library that I can use on backend and frontend.

Thanks in advance.

Kind Regards,
Vini.


#2

Hi,

check out this Kotlin project:


I think gives you an example of the current only available solution (note that you are limited to depend only to kotlin-stdlib-common which is a stripped version of the stdlib for each target, jvm or js - meaning it does not contain compile target specific code)

Study the modules, shared, jvm and js. jvm and js depends on shared where
the shared code lies. You have to have separate modules for each kotlin
compile target (and to fill in the holes of target specific
implementations).

Jørund


#3

Thank you very much Jørund,

I will dive into it.


#4

And if you use gradle, you can also take a look at how kotlin-test library is built, which is also a multiplatform project: https://github.com/JetBrains/kotlin/tree/master/libraries/kotlin.test

Please note that the multiplatform project support is in the pre-release state, so no compatibility guaranties are given whatsoever.