![](/img/trans.png)
[英]Problem with Maven plugin :maven-enforcer-plugin:3.0.0-M3:enforce Some Enforcer rules have failed
[英]Is this the correct way to enforce a specific Spring version using the enforcer plugin?
我希望使用maven-enforcer插件的bannedDependencies规则来强制执行特定的Spring版本(3.1.2)。
这是配置执行程序插件以实现该目标的正确方法吗?
<configuration>
<rules>
<bannedDependencies>
<searchTransitive>true</searchTransitive>
<excludes>
<exclude>org.springframework</exclude>
</excludes>
<includes>
<include>org.springframework:*:3.1.2</include>
</includes>
</bannedDependencies>
</rules>
<fail>true</fail>
<failFast>true</failFast>
<ignoreCache>true</ignoreCache>
</configuration>
上面的代码似乎可以正常工作,并且在命令行上执行了mvn enforcer:enforce
突出显示了v3.1.0或org.springframework:spring-oxm被作为传递依赖项引入。
似乎还可能要使用dependencyConvergence规则,但是它突出显示了许多依赖项错误,这些错误会被maven自动排除为“冲突”。
这是一个包含更多上下文的代码段:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven.enforcer.plugin}</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<bannedDependencies>
<searchTransitive>true</searchTransitive>
<excludes>
<exclude>org.springframework</exclude>
<exclude>org.springframework.security</exclude>
<exclude>org.slf4j</exclude>
</excludes>
<includes>
<include>org.springframework:*:${spring.version}</include>
<include>org.springframework.security:*:${spring-security.version}</include>
<include>org.slf4j:*:${slf4j.version}</include>
</includes>
</bannedDependencies>
<requireJavaVersion>
<version>${enforce.jdk.version}</version>
</requireJavaVersion>
</rules>
<fail>true</fail>
<failFast>true</failFast>
<ignoreCache>true</ignoreCache>
</configuration>
</plugin>
.....
</plugins>
上一个问题中的bannedDependencies
代码段无效,因为<include>
标签无法理解groupId:artifactId:version:type
表示法。 因此,通配符不能用于替换整个部分来传达include all versions of ALL artifacts in a group
。
但是,通过使用maven 依赖关系版本范围 ,可以强制执行特定的依赖关系。
给定工件的以下版本(按发布的顺序):
3.0.0
, 3.0.1
, 3.1.0
, 3.2.0.RELEASE
, 3.3.0
假设我们要告诉3.2.0.RELEASE
执行程序插件排除3.2.0.RELEASE
所有内容,那么唯一的方法是:
exclude versions X where X < DESIRED_VERSION OR X > DESIRED VERSION
上面的意思实际上是: exclude all versions X where X != DESIRED_VERSION
由于Maven依赖版本符号不允许使用“非版本”符号,因此必须结合使用小于和大于符号,如下所示:
(,3.2.0.RELEASE),(3.2.0.RELEASE,)
这意味着: version < '3.2.0.RELEASE' or version > '3.2.0.RELEASE'
。
最后,一段有效的代码片段如下:
<bannedDependencies>
<searchTransitive>true</searchTransitive>
<excludes>
<exclude>org.springframework:*:(,${spring.version}),(${spring.version},)</exclude>
</excludes>
</bannedDependencies>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.