Kotlin2js vs multiplatform gradle plugin

Okay, so I’ve been trying to create a build with Kotlin2Js and with Multiplatform with some common code and some Js and JVM specific code.

It is unclear to me what the recommended approach is, because it appears to be changing. Looking at the docs on multiplatform it clearly favours the multiplatform module. However, the KotlinJS docs show a preference to kotlin2js. Looking to a lot of blog posts in the past week it appears that most people use Kotlin2Js.

Also, the documentation on multiplatform is lacking, since a lot of the magic Kotlin Gradle DSL is very difficult to find. There are multiple ways of defining source sets and dependencies. Delegated properties are used, but they must match the names of the source sets, which seems awkwardly ‘magic’ to me.

What is the state of multiplatform vs kotlin2js and what is the recommended approach if starting today with developing a JVM backend and JS frontend?

I also just found out about the kotlin-frontend-plugin. It is not mentioned anywhere in the docs on the Kotlin website. Is this an official plugin? if so, is it experimental?

A lot of questions, but it is difficult to find a proper source of answers.

1 Like

Kotlin-frontend is being deprecated at the moment.So you’d better to move to kotlin-js plugin.

Thanks, where is this depreciation mentioned then? It is not on the Github page: https://github.com/Kotlin/kotlin-frontend-plugin

And, what is the relation between kotlin-js, kotlin2js and multiplatform? They are largely overlapping, apart from the fact that muktiplatform is much broader and experimental.

I am not sure it is mentioned somewhere, but there were a lot of discussions about it. Kotlin2Js is “old” plugin and probably also will be deprecated after 1.3.50 release. kotlin-js and kotlin-multiplatform share a lot of common code so they have quite similar configuraion. Some things still do not work with kotlin-js, but I think that most of them will be fixed in 1.3.50. If you have some working code, just wait for a while and then migrate to kotlin-js after 1.3.50. Otherwise, you can play with EAP on your own risk (like I did).

Thanks a lot. All the documentation still points to “kotlin2js” and not to “kotlin-js”. So it is difficult for me to locate any information on “kotlin-js”. Where can I find that?

Looking at https://github.com/JetBrains/kotlin/tree/master/libraries/tools/kotlin-gradle-plugin it seems that “kotlin2js” is still used. Searching for any references to “kotlin-js” yields no results.

Am I just looking at the wrong places? The tutorial on the Kotlin site for Javascript is last updated November 4th 2016…

I think the basic information is here: https://blog.jetbrains.com/kotlin/2019/06/kotlin-1-3-40-released/.
Documentation is not ready yet for the new plugin. The tracking issue for documentation is here: https://youtrack.jetbrains.com/issue/KT-32137.

2 Likes