Building a uberjar with Gradle

后端 未结 4 2075
耶瑟儿~
耶瑟儿~ 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:20

    I replaced the task uberjar(.. with the following:

    jar {
        from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {
            exclude "META-INF/*.SF"
            exclude "META-INF/*.DSA"
            exclude "META-INF/*.RSA"
        }
    
        manifest {
            attributes 'Implementation-Title': 'Foobar',
                    'Implementation-Version': version,
                    'Built-By': System.getProperty('user.name'),
                    'Built-Date': new Date(),
                    'Built-JDK': System.getProperty('java.version'),
                    'Main-Class': mainClassName
        }
    }
    

    The exclusions are needed because in their absence you will hit this issue.

提交回复
热议问题