I want to build an uberjar (AKA fatjar) that includes all the transitive dependencies of the project. What lines do I need to add to build.gradle
?
This is what I currently have:
task uberjar(type: Jar) { from files(sourceSets.main.output.classesDir) 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 } }
Gradle ships with a Maven plugin, which adds support to convert a Gradle file to a Maven POM file. It can also deploy artifacts to Maven repositories. The plugin uses the group and the version present in the Gradle file and adds them to the POM file. Also, it automatically takes the artifactId from the directory name.
Shadow is a Gradle plugin for combining a project's dependency classes and resources into a single output Jar. The combined Jar is often referred to a fat-jar or uber-jar.
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.
Have you tried the fatjar example in the gradle cookbook?
What you're looking for is the shadow plugin for gradle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With