Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vincenzopalazzo/7dc0b17715a6197483a753e1094b7d3b to your computer and use it in GitHub Desktop.
Save vincenzopalazzo/7dc0b17715a6197483a753e1094b7d3b to your computer and use it in GitHub Desktop.

Example of jatJar task using Gradle Kotlin DSL:

val mainClass = "com.github.daggerok.Main" // replace it!

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