Maven – Excluding Dependency with Maven Assembly Plugin

mavenmaven-assembly-plugin

I have an assembly project with two direct dependencies, a war and an jar. In the assembly descriptor, I am trying to place the war in one folder and the jar in another. As such, I am using the following dependencySet snippet:

 <dependencySets>
    <dependencySet>
        <outputDirectory>webapps</outputDirectory>
        <includes>
            <include>*:war</include>
        </includes>
        <directoryMode>750</directoryMode>
        <fileMode>660</fileMode>
    </dependencySet>
    <dependencySet>
        <outputDirectory>bin</outputDirectory>
        <includes>
            <include>mygroup:my-jar-artifact</include> 
        </includes>
        <directoryMode>750</directoryMode>
        <fileMode>660</fileMode>
    </dependencySet>
</dependencySets>

However, when I execute "mvn assembly:single", it always ends up placing the jar in the webapps directory. I have tried every possible way to force it to exclude the jar (including adding excludes tags, etc). I know I could do a workaround by using the by using the maven dependency plugin to copy the jar to a folder and then use the assembly descriptor to copy the flat file over. However, I really feel like I ought to be able to use dependency sets to do this. Any ideas?

Additional information:

  • I am using maven 3.0.2 but maven 3.0.3 exhibits the same behavior.
  • My pom dependency for the jar uses a 'jar-with-dependencies' classifier.

Best Answer

Could it be that it is copying transitive dependencies of the WAR?

Try using either

<useTransitiveDependencies>false</useTransitiveDependencies>

or

<useTransitiveFiltering>true</useTransitiveFiltering>

in the dependencySet of the WAR.

Assembly Descriptor documentation

If useTransitiveDependencies is turned off (it is on by default), the transitive dependencies of the WAR should not be copied.

If useTransitiveFiltering is turned on (it is off by default), the filters you define will apply to the transitive dependencies of the WAR, and since this is including *:war should not include any of the dependency JARs when copying.