10

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

Loc Phan
  • 4,304
  • 4
  • 29
  • 35
  • Here is an answer for one particular case http://stackoverflow.com/a/24578209/1531945 In general, manipulating `dependencySets` and `unpackOptions` should do the trick. – Konstantin Pelepelin Oct 31 '16 at 15:52

3 Answers3

7

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>
h3xStream
  • 6,293
  • 2
  • 47
  • 57
Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • I got your idea but It does not work. logback.xml is not included in final jar. Perhaps, the plugin expanded the jars, then package them with the filter (exclude logback.xml) – Loc Phan May 19 '11 at 04:09
  • 1
    This works for me only in the first build after I edit assembly.xml. If I run the build again, it stops working. Seems the order in which resources are copied is undefined, and therefore there is no guarantee this will work. – thegeko Oct 05 '15 at 09:29
3

(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)

  • You could use backticks ` to mark things as `code` in your answer, so e.g. the file name would be more readable then. – mbo Jul 27 '17 at 10:57
1

Is the first artifact a module of your own project? If so, you could exclude the log-back.xml there in the resources section of the pom.xml.

<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 the log-back.xml by itself when it is built out of the scope of the overall jar.

Frank
  • 399
  • 6
  • 15
  • 1
    Unfortunately, I cannot change the first artifact. – Loc Phan May 17 '11 at 07:29
  • Oh, ok, then I think this is going to be difficult. As far as a I know you can only exclude transitive dependencies of dependencies, but not contents that are bundled within a dependency. – Frank May 17 '11 at 08:09