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

Matt Nelson

10/07/2023, 12:15 PM
So, publishing a library to Sonatype. Have some local .jar dependencies that I need to include with the publication. Have no clue how to do that and cannot find anything when searching. Anyone got ideas?
This is my gradle file which shows the jar dependencies for Android and Jvm, as well as the jar repackaging logic https://github.com/toxicity-io/sqlite-mc/blob/master/library/driver/build.gradle.kts
Example: From the snapshots for the android publication you can see the
.jar
files included
but for the
jvm
publication, no additional
.jar
files are included
m

mbonnin

10/07/2023, 2:39 PM
Looks like the jars are shadowed inside the .aar in the android case. It's not a publishing issue, it's about how you build your
driver-jvm-[...].jar
You can customize it with sutff like:
Copy code
tasks.named("jvmJar").configure {
  this as Jar
  from("libs/sqlite-driver.jar)
  from("libs/sqlite-jdbc.jar)
}
Or something along these lines
m

Matt Nelson

10/07/2023, 2:45 PM
Added
Copy code
tasks.withType<Jar> {
    if (name != "jvmJar") return@withType
    from(jdbcRepack.jarSQLiteJDBCJvm)
    from(jdbcRepack.jarSQLDelightDriver)
}
resulting
.jar
file includes the 2 jars. Will this work for library consumers, them being packaged this way?
m

mbonnin

10/07/2023, 2:46 PM
I have no idea but at least it'll look like your android .aar 😄
If those are regular dependencies, the usual way is to have them declared in the .pom/.module file and let Gradle/Maven do their magic during dependency resolution
m

Matt Nelson

10/07/2023, 2:48 PM
Unfortunately, cannot do that. I'm providing a repackaged jar of
xerial/sqlite-jdbc
whereby the native binaries are compiled using
SQLite3MultipleCiphers
, so.
m

mbonnin

10/07/2023, 2:49 PM
So if you want to shadow the usual way is to relocate using something like https://github.com/johnrengelman/shadow
m

Matt Nelson

10/07/2023, 2:50 PM
Yeap, but the JNI interface cannot be relocated sad panda lol
It's a tricky problem, heh
m

mbonnin

10/07/2023, 2:51 PM
the JNI interface cannot be relocated
you "just" have to do it manually 🙈
m

Matt Nelson

10/07/2023, 2:51 PM
oh fml, lol
m

mbonnin

10/07/2023, 2:51 PM
😂
You can shadow without relocation but then it will clash if someone tries to pull the same dependency
Pretty sure there is a
from()
call that "expands" the zip. Maybe zipTree or something
Copy code
tasks.withType<Jar> {
    if (name != "jvmJar") return@withType
    from(zipTree(jdbcRepack.jarSQLiteJDBCJvm))
}
Then it will put all the .class files in your jar
If you have JNI, you should also copy the
.so
native libs too
m

Matt Nelson

10/07/2023, 2:57 PM
Yep, using
zipTree
includes them
That worked out. Different project, tests run now for both Android and Jvm using the publications
🎉 1