https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
d

David Herman

03/29/2023, 2:53 PM
If I'm using the Kotlin multiplatform plugin to create a JS library, and I'm sure I'll only be releasing that target, is it safe for me to exclude the multiplatform publication when generating artifacts for Maven?
1
In other words, if I have a library called "mylib", instead of creating "mylib" and "mylib-js" artifacts, I think I can change it so the JS target gets published as "mylib" and the multiplatform version gets ignored.
Then, a user would just add a dependency on the library inside their
jsMain
dependency block.
Does that make sense? Does the common multiplatform artifact contain any metadata that's important in some subtle way?
b

Big Chungus

03/29/2023, 3:13 PM
At this point you might just want to switch to kotlin.js gradle plugin instead of using mpp
d

David Herman

03/29/2023, 3:21 PM
I need mpp for Compose support
b

Big Chungus

03/29/2023, 3:21 PM
I thought CfW already supports js plugin. Have you tried recently?
c

CLOVIS

03/29/2023, 3:21 PM
Maybe you can create a new project with
kotlin("js")
, no code but a dependency on your MPP project, and publish that one?
d

David Herman

03/29/2023, 3:23 PM
I haven't tried recently, but I don't want to restructure all my existing code if I can just tweak the publication configuration. This question could probably also apply to K/N targets.
c

CLOVIS

03/29/2023, 3:24 PM
I've heard in the Gradle slack that touching publishing is generally not recommended as it can break included builds. No idea if that's the case here, though.
b

Big Chungus

03/29/2023, 3:24 PM
Well I don't see why your initial idea would not work, but that just smells like a messy gradle setup imho
I personally would invest in restructuring to use js plugin. Much easier to maintain than custom patches
d

David Herman

03/29/2023, 3:25 PM
I guess my fundamental question is if the publication created by the js plugin is different from the JS part published by the multiplatform plugin
b

Big Chungus

03/29/2023, 3:26 PM
Shouldn't be (other than -js suffix)
d

David Herman

03/29/2023, 3:26 PM
Thanks
And I'll double check if the Kotlin/js plugin approach works instead.
r

Robert Jaros

03/29/2023, 3:41 PM
I've heard JB is planning to drop kotlin/js plugin and use only kotlin/mpp js target in the future. So migration to kotlin/js plugin when you have mpp already working is probably not the best idea.
c

CLOVIS

03/29/2023, 4:07 PM
Any source on that?
Honestly I'd be for it, it's painful to create convention plugins for Kotlin, I often have JVM+JS library modules, a JVM backend and a JS frontend
d

David Herman

03/29/2023, 4:12 PM
@Big Chungus so I just did an experiment trying to convert one module to the kotlin/js plugin, and this section now causes import problems:
Copy code
val jsMain by getting {
   dependencies {
      implementation(compose.runtime)
      implementation(compose.web.core)
   }
}
since it seems that (as far as I can tell from some quick code searching) the compose plugin does not export convenient version catalogs for platform specific compose targets. (In a multiplatform world, these implementation declarations are resolved correctly) I can of course add them myself, but it feels like I'm going against the grain here. Not to mention that the Kotlin/JS plugin just looks like the Kotlin/Multiplatform plugin if you squint (you still need to create a
kotlin { js { ... } }
configuration block, same as multiplatform, and the type of the
kotlin
block is
KotlinMultiplatformExtension
A picture is worth 1000 lines of code:
@Robert Jaros thanks for the heads up! Confirmation would be great but I'll be careful for now about jumping on a migration.
c

CLOVIS

03/29/2023, 4:17 PM
I'm genuinely considering migrating all my projects to the MPP plugin for the sole reason that the tasks would follow the same naming conventions everywhere
r

Robert Jaros

03/29/2023, 4:17 PM
@CLOVIS JB gave me some early hints about their plans, because KVision is currently based on kotlin/js plugin.
c

CLOVIS

03/29/2023, 4:18 PM
Nice!
b

Big Chungus

03/29/2023, 4:28 PM
Rename jsMain to main and it should work
e

eygraber

03/29/2023, 5:03 PM
I think I remember @Sebastian Sellmair [JB] mention in a KMP meetup that there's a chance (if not a plan) that long term everything will be built on KMP's gradle model.
d

David Herman

03/29/2023, 5:18 PM
@Big Chungus Yeah, I understand that I'd need to migrate "jsMain" to "main". I was hoping to show two things off in the screenshot though: 1) this build script is failing at configuration time, and 2) the type of the
kotlin
block is
KotlinMultiplatformExtension
even though it's being exposed by the JS plugin (which makes me suspect it's really the multiplatform plugin but tweaked).
b

Big Chungus

03/29/2023, 5:28 PM
Ah, yes, missed that point. Yeah the two are actually bundled in a same jar and reuses a lot of stuff so that's not unexpected.
d

David Herman

03/29/2023, 5:31 PM
Cool. I'm just figuring things out as I go along -- I appreciate the help!
s

Sebastian Sellmair [JB]

03/30/2023, 7:36 AM
I do not recommend migrating to the -js plugin. I know that our current policy was oscillating with the plugins, but we seem to converge with the mpp plugin as the one that should be used also for js only. Regarding publication of the root vs the -js modules: Yes, feel free to not publish the root when you only target js and never plan to extend it.
6 Views