If I want to publish the Kotlin/Native library to ...
# kotlin-native
s
If I want to publish the Kotlin/Native library to be used by another project (kotlin multiplatform project for example), what is the best way to publish it? The way i understand it, kotlin native would mean many different hardward architecture. So, for the dependency manager via something with
implementation()
on gradle, how does it resolve the architecture to download? Currently I have a publication on maven, but I'm also uploading the
.klib
. Is there a way to avoid that so that I won't have to upload separate publications for all the hardwares I want to support? I'm sorry this is like a long multi-question question, but I've been wrecking my brain trying to make this work... Help please.
k
This is handled with gradle metadata. A single “library” will publish several actual artifacts, but the target is ultimately chosen by gradle by way of metadata attributes.
Those are all published artifacts
s
Oh, interesting. So, now, when trying to use in the dependencies block, you could just do
squilter
, for any native components, and it would know which one to get?
k
Your common dependency would still be
implementation 'co.touchlab:sqliter:0.6.4'
and gradle would sort it out (assuming you were on a sufficiently recent version of gradle)
Yes
s
So, if common dependency would be
implementation 'co.touchlab:sqliter:0.6.4'
, and then what would be the native dependency?
implementation 'co.touchlab:sqliter:0.6.4'
too?
k
Yes, could be. sqliter is a bad example as it’s really just for native, even though I publish a jvm artifact.
s
Ahh, I see. That makes so much sense now
k
You could put that dependency in common or in the native deps and it would find it
s
That's pretty great. Yeah, do use
5.6.2
gradle, so I should be good on that
So, in theory, it is possible to have
implementation 'co.touchlab:sqliter:0.6.4'
for all the platforms including the
jvm/android
one?
k
Yeah, it’s a lot more fun now that the metadata is 1.0. Pre 1.0, each library needed to be republished for different ranges of gradle
s
Wow. That's really great!
k
Yes. Stately is a better example. There’s jvm and native, and you just reference the common dependency.
For “shared prefs”
One of the talks I’ve overcomitted myself to is libraries …
s
That's pretty cool. So, in our readme, I guess we have to say which particular native arch do we support?
That's fantastic @kpgalligan. I'm really looking forward to those talks
k
Yeah. That is a tricky thing. I originally had no linux or windows, but it turns out people actually use them…
🙄 1
Haven’t published a wasm or native android lib yet, though
s
😄
Cool. I think its all about the principle that I was really missing here. That's what we need for people trying to make this jump I think
k
I’ve spent the whole day working on concurrency talk. As mentioned, that’s I think the really big one. For libraries, understanding what gradle does with them is super important. Can’t use jitpack, btw
s
Yeah, that was my first attempt. Jitpack. We have used jitpack here so far. Now, looks like we are moving out
k
There is (I think) experimental support for building windows from a mac machine, but not sure where that is. I currently build windows from parallels. Assume windows isn’t a big priority, but depending on what you’re building, it may get requested
s
That's interesting. Yeah, at the moment, we are not very windows friendly. But, definitely something we might in the future