Cjxcz Odjcayrwl
Cjxcz Odjcayrwl

Reputation: 22847

Maven depenency plugin : copy dependencies : exclude single artifact

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?

Upvotes: 8

Views: 9602

Answers (1)

Marinos An
Marinos An

Reputation: 10808

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>

Upvotes: 13

Related Questions