【发布时间】:2016-05-06 06:53:22
【问题描述】:
我目前正在尝试的是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<banTransitiveDependencies>
<excludes>
<exclude>*:*:*</exclude>
</excludes>
<includes>
<include>commons-lang:commons-lang:2.4</include>
</includes>
</banTransitiveDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>
我上面尝试的意图是:
排除禁止所有传递依赖,除了 commons-lang:2.4
当我尝试时
mvn verify
我会得到
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-banned-dependencies) @ ebtam-core ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
这不好。因为我知道我的项目中有以下依赖项:
[INFO] +- org.apache.velocity:velocity:jar:1.6.2:compile
[INFO] | +- commons-lang:commons-lang:jar:2.4:compile
我做错了什么?
【问题讨论】:
-
我不能肯定地说(这就是为什么这是评论,而不是答案),但不是反过来吗?您想从禁令规则中排除 commons-lang,但强制禁止其他所有内容。所以你的 ::* 被包括在内,而 commons-lang:commons-lang:2.4 被排除在外。这就是我从maven.apache.org/enforcer/enforcer-rules/…理解它的方式@
-
@Creperum 不,我想排除所有内容,包括 commons-lang。
-
如果你想禁止 commons-lang 依赖,你只需要像你已经做的那样定义包含,但你必须删除排除。
-
@khmarbaise 但是包含只是覆盖排除,不是吗?
-
排除优先....通常您排除特定工件/版本等...
标签: java maven dependencies