Skip to content

Instantly share code, notes, and snippets.

@Renkai
Created August 22, 2018 08:17
Show Gist options
  • Save Renkai/58ec2272f3d614baa8fdb4e3778481a1 to your computer and use it in GitHub Desktop.
Save Renkai/58ec2272f3d614baa8fdb4e3778481a1 to your computer and use it in GitHub Desktop.
create fat jar with gradle kotlin dsl
tasks.create<Jar>("fatJar") {
appendix = "fat"
setDuplicatesStrategy(DuplicatesStrategy.FAIL)
manifest {
attributes(mapOf("Main-Class" to "Main")) // replace it with your own
}
val sourceMain = java.sourceSets["main"]
from(sourceMain.output)
configurations.runtimeClasspath.filter {
it.name.endsWith(".jar")
}.forEach { jar ->
from(zipTree(jar))
}
}
@daggerok
Copy link

daggerok commented Mar 31, 2019

not worked for me in case smallrye microprofile...

I found, that this one is working as expected:

tasks {
  register("fatJar", Jar::class.java) {
    archiveClassifier.set("all")
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    manifest {
      attributes("Main-Class" to mainClass)
    }
    from(configurations.runtimeClasspath.get()
        .onEach { println("add from dependencies: ${it.name}") }
        .map { if (it.isDirectory) it else zipTree(it) })
    val sourcesMain = sourceSets.main.get()
    sourcesMain.allSource.forEach { println("add from sources: ${it.name}") }
    from(sourcesMain.output)
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment