Building an uberjar with Gradle
Have you tried the fatjar example in the gradle cookbook?
What you're looking for is the shadow plugin for gradle
How do I create an executable fat JAR with Gradle with implementation dependencies?
You can use the following code.
jar {
manifest {
attributes(
'Main-Class': 'com.package.YourClass'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Be sure to replace com.package.YourClass
with the fully qualified class name containing static void main( String args[] )
.
This will pack the runtime dependencies. Check the docs if you need more info.
Using Gradle to build a JAR with dependencies
I posted a solution in JIRA against Gradle:
// Include dependent libraries in archive.
mainClassName = "com.company.application.Main"
jar {
manifest {
attributes "Main-Class": "$mainClassName"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Note that mainClassName
must appear BEFORE jar {
.
How to build uberJar with Quarkus-Gradle-Plugin
The name of that option is "uber-jar".
To set this property you have to start the build like that from command line:
>gradle quarkusBuild --uber-jar
I had some bugs during the build, like that one
Caused by: java.nio.file.NoSuchFileException: /Users/sven/Idea/getting-started/build/getting-started.jar
but in the end the build was successful
Gradle 7 create a fat jar
Use configurations.runtimeClasspath
instead of configurations.compileClasspath
. compileClasspath
contains all libraries required for compilation, thus fastutil
is included. runtimeClasspath
on the other hand excludes libraries from configuration compileOnly
.
Creating an executable fat jar with dependencies (gradle or maven)
You can add a manifest to your task since it is type Jar. Specifying an entrypoint with the Main-Class attribute should make your Jar executable.
task uberJar(type: Jar) {
manifest {
attributes 'Main-Class': 'your.main.class.goes.here'
}
archiveClassifier = 'uber'
from sourceSets.main.output
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
}
}
Related Topics
Preparedstatement Syntax Error
How to Insert an Pdpage Within Another Pdpage with PDFbox
Should I Use a Separate Scriptengine and Compiledscript Instances Per Each Thread
Java.Net.Socketexception: Software Caused Connection Abort: Recv Failed
Fetch First Element of Stream Matching the Criteria
Jtable How Prepareeditor Works
How to Escape Reserved Words in Hibernate's Hql
What Is the Point of Getters and Setters
Animate JPAnel (Slide In) with Timer
Java Date Cut Off Time Information
Jframe.Dispose() VS System.Exit()
Java Two Varargs in One Method
Self Signed X509 Certificate with Bouncy Castle in Java
How to Create New Xml File from Existing Database in Postgresql Database Using Java