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

svenjacobs

09/22/2023, 12:02 PM
Hey, can somebody please explain when I use a KMP library like for example cache4k in a pure (non-multiplatform) Android project, which part of the build system is responsible for fetching the proper artifact? For instance when I declare the dependency as
implementation("io.github.reactivecircus.cache4k:cache4k:x.y.z")
it actually needs to load
cache4k-jvm
. Is it Gradle, the Kotlin Gradle plugin or the Android Gradle plugin which is responsible for this and is there a specific version requirement of these build components so that it works with KMP libraries? Or in other words: When did this start to work? 🙂
c

Casey Brooks

09/22/2023, 3:10 PM
Both Gradle and Kotlin are responsible for it. Historically, JVM libraries built with Maven, Gradle, and other build systems would publish their
.pom
file which describes a libraries dependencies and some other basic info. But Gradle also publishes an additional
.module
JSON file, which is Gradle Module Metadata. The KMP Gradle plugin was one of the first to adopt this module metadata to specify constraints of things like MPP target or JDK version. Gradle considers module metadata published by the Kotlin plugin for matching the “common” coordinates to the target-specific artifacts
For consuming KMP artifacts in a pure Android project, I don’t think it’s usually necessary to specify the
-jvm
suffix, since Gradle should still be looking at the module metadata when resolving those dependencies. I think some of those libraries do explicitly specify it for historical reasons, because earlier versions of AGP didn’t consider the module metadata or something like that. I’m not fully sure about this, though.
s

svenjacobs

09/22/2023, 3:19 PM
Thanks @Casey Brooks for the details. Do you by any chance know which version of AGP is required so that I as a KMP library developer can mention this in my README?
c

Casey Brooks

09/22/2023, 3:22 PM
Like I mentioned, I’m not even sure is that’s the reason why some libraries specify it. I think you’re probably fine to just include the common coordinates in your documentation. That’s what I do with the libraries I manage, and I’ve never heard of anyone not able to use it on Android because they didn’t specify
-jvm
suffix
👍 1
4 Views