Uber JAR with Gradle Kotlin DSL

In this article, we will find a solution to the question – how to make an uber jar Gradle Kotlin DSL or how to make a fat jar Gradle Kotlin DSL.

Let’s add this to build.gradle.kts file:

tasks.register<Jar>("uberJar") {
    archiveClassifier.set("uber")
    from(sourceSets.main.get().output)
    dependsOn(configurations.runtimeClasspath)
    from({
        configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
    })
}

After that, you can build the jar with dependencies:

./gradlew uberJar

That’s all.

Possible errors

Error: no main manifest attribute, in /path/to/your/jar
You need to add a key to your manifest containing the full name of the main class. I described how to do this in this article: https://mchesnavsky.tech/no-main-manifest-attribute-gradle-kotlin-dsl/

Error: Invalid signature file digest for Manifest main attributes.
You need to exclude files with extensions .SF, .DSA, .RSA from the assembly.
I described how to do this in this article: https://mchesnavsky.tech/invalid-signature-file-digest/

If you still have any questions, feel free to ask me in the comments under this article, or write me on promark33@gmail.com.

If I saved your day, you can support me :)

Leave a Reply

Your email address will not be published.