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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With