https://kotlinlang.org logo
k

Kris Wong

01/08/2020, 5:41 PM
has anyone setup an MPP to build a fat jar? or configured the java/shadow plugins?
Copy code
tasks.register<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
    val target = kotlin.targets["jvm"]
    dependsOn(target.artifactsTaskName)

    group = "shadow"
    description = "Builds a fat jar"

    val compilation = target.compilations["main"] as org.jetbrains.kotlin.gradle.plugin.KotlinCompilationToRunnableFiles
    from(compilation.output)
    configurations = listOf(compilation.runtimeDependencyFiles as Configuration)
}
d

Dico

01/09/2020, 1:49 AM
I tend to simply collect all compile dependencies into an archive task. No plugins required.
Copy code
val jvmFatJar by tasks.creating(Jar::class) {
    // set name & path
    from(*configurations["jvmMainCompile"].resolvedConfiguration.files.map { if (it.isFile) zipTree(it) else it }.toTypedArray())
}
Something like this, you may need to use
afterEvaluate
Might be able to improve it with new model.
k

Kris Wong

01/09/2020, 2:12 AM
yeah, that's way outside my wheelhouse, and already using shadow on another project
but thanks!
2 Views