How do I create an executable fat jar with Gradle with implementation dependencies

前端 未结 5 599
广开言路
广开言路 2020-12-01 09:02

I\'ve got a simple project in Gradle 4.6 and would like to make an executable jar of it. I\'ve tried shadow, gradle-fatjar-plugin, gradle-one

5条回答
  •  感动是毒
    2020-12-01 09:23

    Based on the accepted answer, I needed to add one more line of code:

    task fatJar(type: Jar) {
      manifest {
        attributes 'Main-Class': 'com.yourpackage.Main'
      }
      archiveClassifier = "all"
      from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
        }
      with jar
    }
    

    Without this additional line, it omitted my source files and only added the dependencies:

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

提交回复
热议问题