问题描述
我需要从 maven-depence-plugin:copy-dependencies 中排除单个工件.
I need to exclude single artifact from maven-depencency-plugin:copy-dependencies.
在文档上:https://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html 我发现了两个有趣的选项:
On the docs: https://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html I've found 2 interesting options:
excludeArtifactIds 将排除所有与给定工件 ID 匹配的工件(组 ID 上的通配符)
excludeArtifactIds which will exclude all artifacts matching given artifact-id (wildcard on group-id)
excludeGroupIds 将排除所有与给定组 ID 匹配的工件(工件 ID 上的通配符)
excludeGroupIds which will exclude all artifacts matching given group-id (wildcard on artifact-id)
如果给定工件的 group-id 或 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?
推荐答案
您可以通过使用两个 execution
部分来实现这一点.
You can achieve this by using two execution
sections.
假设您有以下依赖项:
javax.mail:mailapi
javax.mail:mail
sun-javamail:mail
org.jdom:jdom2
并且您只想排除与其他工件共享 groupId 和 artifactId 的 javax.mail:mail
.
and you only want to exclude javax.mail:mail
which shares both groupId and artifactId with other artifacts.
以下方法可以做到:
<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>
这篇关于Maven 依赖插件:复制依赖:排除单个工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!