Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven depenency plugin : copy dependencies : exclude single artifact

Tags:

maven

I need to exclude single artifact from maven-depencency-plugin:copy-dependencies.

On the docs: https://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html I've found 2 interesting options:

excludeArtifactIds which will exclude all artifacts matching given artifact-id (wildcard on group-id)

excludeGroupIds which will exclude all artifacts matching given group-id (wildcard on artifact-id)

This would work, if either group-id or artifact-id of given artifact were unique. Is it possible to exclude a single artifact, without using wildcards?

like image 580
Danubian Sailor Avatar asked Feb 23 '17 10:02

Danubian Sailor


1 Answers

You can achieve this by using two execution sections.

Let's say you have the following dependencies:

javax.mail:mailapi
javax.mail:mail
sun-javamail:mail
org.jdom:jdom2

and you only want to exclude javax.mail:mail which shares both groupId and artifactId with other artifacts.

The following would do it:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <!--include all in group apart from one-->
                    <configuration>
                        <excludeArtifactIds>mail</excludeArtifactIds>
                        <includeGroupIds>javax.mail</includeGroupIds>
                    </configuration>
                </execution>
                <execution>
                    <id>copy-dependencies2</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <!--include all other dependencies-->
                    <configuration>
                        <excludeGroupIds>javax.mail</excludeGroupIds>
                    </configuration>
                </execution>                    
            </executions>                
        </plugin>
like image 141
Marinos An Avatar answered Nov 01 '22 13:11

Marinos An