Josh Harness
Josh Harness

Reputation: 477

Excluding Dependency with Maven 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:

Upvotes: 1

Views: 6873

Answers (3)

Josh Harness
Josh Harness

Reputation: 477

I figured it out. I was going to look at the source code for the assembly plugin to figure out the problem. In doing so, I noticed that I was using assembly 2.2-beta-1. Upgrading to 2.2 fixed the issue entirely. Lesson learned that I should always check the version of the plugin next time.

Upvotes: 0

Raghuram
Raghuram

Reputation: 52665

Another possibility is the syntax *:war is incorrect.

Can you try specifying the groupId:artifactId explicitly in the <include>, the same way that you have done for the jar artifact?

<includes>
    <include>mygroup:my-war-artifact</include> 
</includes>

Upvotes: 0

prunge
prunge

Reputation: 23268

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.

Upvotes: 1

Related Questions