Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overwrite resource file with maven assembly plugin

I use maven-assembly-plugin with "jar-with-dependencies" to package jar. There are 2 dependencies artifact having log-back.xml. The second artifact is depend on the first one. I want to have log-back.xml of the second artifact in final jar, but it always contain log-back.xml of the first one. So how can I control this?

Thanks

like image 630
Loc Phan Avatar asked May 17 '11 07:05

Loc Phan


2 Answers

You can use the unpackOptions to achieve this. Try something like 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>
like image 198
Raghuram Avatar answered Oct 10 '22 11:10

Raghuram


(With last version of maven-assembly-plugin at this time : 3.0.0)

I had the same problem with an assembly build.

I had tow dependencies with the same properties file but with a different content (one good and the other overwritting the first with missing declarations).

The problem was that i finally had the bad configuration file replacing the other in my assembly jar.

The only cleanest solution i found to overwrite the file was to :

1 - Add the good file that i wanted to keep for the build in my project : ex: src/main/resources/META-INF/services/myfileWhichOverwriteTheBadDependenciesRessources.xml

2 - Add a fileset with 'filtered' setted to 'true' in my assembly descriptor :

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

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

like image 35
Charles Vuillecard Avatar answered Oct 10 '22 13:10

Charles Vuillecard