Building a uberjar with Gradle

后端 未结 4 2080
耶瑟儿~
耶瑟儿~ 2020-11-27 04:28

I am a Gradle novice. I want to build a uberjar (AKA fatjar) that includes all the transitive dependencies of the project. What lines do I need to add to my \"build.gradle\"

4条回答
  •  面向向阳花
    2020-11-27 05:24

    Simply add this to your java module's build.gradle.

    mainClassName = "my.main.Class"

    jar {
      manifest { 
        attributes "Main-Class": "$mainClassName"
      }  
    
      from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
      }
    }
    

    This will result in [module_name]/build/libs/[module_name].jar file.

提交回复
热议问题