I have a java program with a simple main class that depends on libraries a.jar, b.jar, c.jar. How do I make it such that I can create a runnable jar file with all those jars properly packaged?
I know in the jar task, you need to include:
apply plugin: 'java'
apply plugin:'application'
repositories {
mavenCentral()
}
jar {
manifest {
attributes 'Main-Class': 'com.foo.bar.MainClass'
}
}
But do not know what to do with the three external jars that my code uses.
The easiest way is to merge the dependency Jars into the main Jar:
jar {
from "path/to/jar1", "path/to/jar2"
}
Or, if the Jars are retrieved from a Maven/Ivy repository:
jar {
from configurations.runtime
}
Alternatively, you can use a plugin such as gradle-onejar, which covers more use cases.
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