Log4j.properties is overwritten when creating a "fat-JAR" using Gradle

One of my Java projects is exporting a fat-JAR executable ready for deployment. To create a JAR file using Gradle, I followed these instructions 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 shown task will recursively go through the dependency tree, if necessary, unzip the JAR and squash all 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 wrote myself. All of them are on the same level with the corresponding folders resources, so when files are merged together, the later ones seem to overwrite the ones that were added earlier.

So far, the only solution I have found is to manually set the path to the correct file using the command line option. Ultimately, I would like to execute the JAR myself without the extra overhead.

What would be a good way to save my log4.properties and prevent others from being added to the package?

+5
source share
1 answer

You can exclude a file from a collection of files for combining in a JAR assembly.

 from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } { exclude "dir/subdir/the_file_to.exclude". } 
+2
source

Source: https://habr.com/ru/post/1259661/


All Articles