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

GarouDan

06/16/2020, 12:56 PM
Hello, If we publish a kotlin mpp library for bintray, for example, I’ve seen that by default all publications go inside the same folder version (
js
,
jvm
,
macosX64
, etc.). But when our client is consuming the library with:
implementation("com.company:project:1.0.0")
It cannot be automatically choose the correct one, for example, a jvm gradle kts project does not work with this from my tests. Can we still use this way or need we publish everything separately? If we can use together, how can we do it?
implementation("com.company:project-jvm:1.0.0")
implementation("com.company:project-js:1.0.0")
implementation("com.company:project-macos_x64:1.0.0")
a

araqnid

06/16/2020, 1:10 PM
consuming just the
:project:
version should be fine with a recent-enough version of Gradle, provided that the Gradle module metadata file has been published too — which should be happening automatically.
I did have one case of having to manually specify the platform attribute to consume an MP module from a JVM-only project:
Copy code
configurations {
    val platformAttr = Attribute.of("org.jetbrains.kotlin.platform.type", org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType::class.java)
    all {
        attributes.attribute(platformAttr, org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.jvm)
    }
}
g

GarouDan

06/16/2020, 2:28 PM
Hum, in my case I think it will be a bit different, the project will be consumed externally, from bintray, for example. So something like
:project
will not be available there, do you know if the metadata will also work in this case? Also, I don’t know how yet, I’d like to distribute the library in a way that people from NodeJS and C/C++ could consume it too. I’m already using the related targets and source sets, but I don’t know how to distribute in a way it will be good for them to consume
l

louiscad

06/16/2020, 4:22 PM
There's a kotlinMultiplatform publication that I don't recall if it's enabled by default. Anyway, you can search on this page: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html
r

russhwolf

06/16/2020, 4:48 PM
It should be handled automatically if you have metadata enabled. So
enableFeaturePreview("GRADLE_METADATA")
in settings.gradle(.kts), which is on by default in Gradle 6+
g

GarouDan

06/16/2020, 4:53 PM
Hum, cool, that’s my case. But one doubt of mine is, what should I do if I’d like to publish the js library for npm as well (maybe also to another place for c/c++ libraries as well)? I’d like to configure in a way that kotlin jvm, js, native project could consume (if Gradle 6 is enough so I’m good) and also I’d like to publish a js version of the library (for nodejs) for npm and in one other place that I don’t know something for C/C++ as well. Since all of them could take benefit from the library.
r

russhwolf

06/16/2020, 4:55 PM
Yeah the automated stuff just helps for consuming via gradle within other Kotlin projects. You'd have to manually configure stuff for NPM or other sorts of distribution
You could ask around in #javascript to see if they have any helpful builtins for NPM publishing but I don't know my way around that side of things yet
g

GarouDan

06/16/2020, 4:57 PM
Yes, I’ll do that. I also found this link here, I need to take a look later, but seems interesting: https://medium.com/swlh/kotlin-to-jar-and-npm-87a5b0ca2dff
👍 1
r

russhwolf

06/16/2020, 4:59 PM
Give it a try, but if that was written last July the JS stuff might be outdated,
g

GarouDan

06/16/2020, 5:00 PM
Yeah, I was thinking exactly that. I dropped a question in the js channel as well.
a

andylamax

06/17/2020, 12:26 AM
Experienced this a while back. Problem is that, the the bintray - plugin. doesn't upload .module files, which are the ones containing metadata generated for gradle. and are used to disambiguate between the target libs.
g

GarouDan

06/17/2020, 12:45 AM
Hum, I’m facing this issue right now. Have you been able to solve this problem? I’ve seen that if I use
library-jvm
instead of
library
seems to work, but no automatically resolution seems to work
r

russhwolf

06/17/2020, 12:46 AM
g

GarouDan

06/17/2020, 12:50 AM
Oh, cool, thanks a lot. I’ll try here 🙂
a

araqnid

06/17/2020, 12:51 AM
I think this might have been one of the reasons I moved away from the bintray plugin to use the standard maven-publish plugin
r

russhwolf

06/17/2020, 12:51 AM
yeah that's been on my TODO but that workaround helped me in the meantime
g

GarouDan

06/17/2020, 1:14 AM
This is strange. It doesn’t work for me, but the
.module
file is already there now, using the workaround. Locally (from my local maven repo), I’ve confirmed that it can be automatically resolved, but when using bintray seems not to work, even when having the
.module
there.
r

russhwolf

06/17/2020, 3:10 AM
You might need
enableFeaturePreview("GRADLE_METADATA")
in your settings.gradle
l

louiscad

06/17/2020, 7:12 AM
The maven-publish plugin supports parallel uploading since Gradle 5.6. I tried it and adopted it for all my projects as the bintray plugin is both no longer necessary and no longer maintained.
2 Views