0

I have a gradle java project and i am trying to fatjar it with dependencies included.

My gradle version is 6.9.2

I have tried the following tasks:

jar {
    manifest {
        attributes "Main-Class": "com.baeldung.fatjar.Application"
    }

    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

And

task customFatJar(type: Jar) {
    manifest {
        attributes 'Main-Class': 'com.baeldung.fatjar.Application'
    }
    baseName = 'all-in-one-jar'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

It jars the project but dependencies are always excluded. Please help.

Lazaruss
  • 1,107
  • 1
  • 13
  • 24

1 Answers1

1

This works :

task uberJar(type: Jar) {
    archiveClassifier = 'uber'

    from sourceSets.main.output

    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
    }
}
Lazaruss
  • 1,107
  • 1
  • 13
  • 24