Overwrite resource file with maven build plugin

I am using maven-assembly-plugin with "jar-with-dependencies" to package jar. There are 2 dependent artifacts having log-back.xml. The second artifact depends on the first. I want to have log-back.xml of the second artifact in the last jar, but it always contains log-back.xml of the first. So how can I control this?

thanks

+7
source share
3 answers

You can use unpackOptions for this . Try the following:

<assembly> ... <dependencySets> <dependencySet> <outputDirectory>/</outputDirectory> <includes> <include>${groupId}:${artifact.whose.logback.is.to.be.excluded} </include> </includes> <unpack>true</unpack> <unpackOptions> <excludes> <exclude>**/logback.xml</exclude> </excludes> </unpackOptions> </dependencySet> <dependencySet> <outputDirectory>/</outputDirectory> <excludes> <exclude>${groupId}:${artifact.whose.logback.is.to.be.excluded}</exclude> </excludes> <unpack>true</unpack> </dependencySet> </dependencySets> </assembly> 
+5
source

Is the first module artifact of your own project? If so, you can exclude the log-back.xml file in the pom.xml resource section.

 <resources> <resource> <directory>src/main/resources</directory> <excludes> <exclude>log-back.xml</exclude> </excludes> </resource> ... </resources> 

However, this only works if this module does not require log-back.xml itself, when it is built from the volume of a common jar.

+1
source

(with the latest version of maven-assembly-plugin currently: 3.0.0)

I had the same problem with assembly build.

I had buffer dependencies with the same properties file, but with different content (one is good and the other is the first with missing ads).

The problem was that in the end I had a bad configuration file replacing another in my assembly.

The only clean solution I found to overwrite the file was as follows:

1 - Add a nice file that I wanted to save for assembly in my project: ex: src/main/resources/META-INF/services/myfileWhichOverwriteTheBadDependenciesRessources.xml

2 - add the set of files with the 'filter' set to 'true' in my build descriptor:

  <fileSet> <directory>${project.main.resources}/META-INF</directory> <outputDirectory>META-INF</outputDirectory> <filtered>true</filtered> </fileSet> 

(the property "project.main.resource" in my case is set to "src / main / resources")

0
source

All Articles