Building \"Fat Jars\" with Gradle
Wednesday, September 04, 2013 |Sometimes, such as when building command line Java apps, it would be nice to bundle all of the app’s dependencies in a single jar so that the user need not collect and manage these. With Gradle, that can be easily accomplished with the following lines:
1
2
3
4
5
6
7
8
9
10
jar {
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
When you run gradle assemble
, you should find your now very hefty jar in build/libs
.