One of my Java projects exports an executable "fat-JAR" file ready for deployment. For creating the JAR file using Gradle, I followed the instructions described here:
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': '<HUMAN_READABLE_TITLE_OF_YOUR_PACKAGE>',
'Implementation-Version': version,
'Main-Class': '<PATH_TO_THE_MAIN_APPLICATION_CLASS>'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
The task illustrated will recursively go through dependency tree, unzip JARs if needed, and squash everything together. The only problem so far is that some of my dependencies come with their own log4.properties
files, which eventually overwrite the one I have written myself. All of them reside within the same level into their respective resources folders
, so when files get merged together, the later ones seem to overwrite the ones that have been added before.
So far, the only solution I have found, is to manually set the path to the right file, using a command-line parameter. I would eventually like to be able to execute the JAR itself, without additional overhead.
What would be a good way to keep my log4.properties
and exclude the others from being added to the package?
You can exlude the file from the collection of files to be merged into the build JAR.
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
} {
exclude "dir/subdir/the_file_to.exclude".
}
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