how do I generate a farJar for a multiplatform project? I get weird dependency resolution errors (can't reconfigure commonApi?) when I try some of the things I found on the web (involving customising the jar task)
czuckie
05/15/2023, 7:38 AM
I was able to accomplish this using the following:
Copy code
kotlin {
jvm() {
compilations {
val main = getByName("main")
tasks {
register<Jar>("buildFatJar") {
group = "application"
dependsOn(build)
manifest {
attributes["Main-Class"] = "my.package.MainKt"
}
excludes += "META-INF/versions/9/module-info.class"
from(configurations.getByName("jvmRuntimeClasspath").map { if (it.isDirectory) it else zipTree(it) }, main.output.classesDirs)
archiveBaseName.set("${project.name}-jar")
}
}
}
...
t
Tóth István Zoltán
05/15/2023, 8:13 AM
I typically use the shadow plugin for that:
Copy code
plugins {
id("com.github.johnrengelman.shadow") version "7.1.2"
}
tasks {
shadowJar {
mergeServiceFiles()
// minimize() // do not use minimize!!!
}
}
have you tried it with a multiplatform project Tóth?
t
Tóth István Zoltán
05/16/2023, 11:34 AM
Yes, I work almost exclusively with multiplatform. The example project above builds a distribution zip which contains all the JVM and JavaScript needed. It also builds a docker image which contains everything.