[英]Why does maven-enforcer-plugin detect maven 3.2.5 when it's run with 3.1.1 on travis-ci.org?
I have a project document-scanner-aggregator which runs fine locally when run with Maven 3.1.1, ie ~/apache-maven-3.1.1/bin/mvn clean install
, but doesn't on travis-ci.org where it detects Maven 3.2.5 which suspiciously is the version provided by travis-ci.org. 我有一个项目文档扫描器聚合器 ,在使用Maven 3.1.1运行时可以在本地正常运行,即
~/apache-maven-3.1.1/bin/mvn clean install
,但不在travis-ci.org上检测到Maven 3.2.5,它可疑是travis-ci.org提供的版本。 However it's not supposed to do that, because the Maven version which runs the build is supposed to be enforced, right? 但是,不应该这样做,因为应该运行运行该构建的Maven版本,对吗?
The failure is 失败是
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireMavenVersion failed with message:
Detected Maven Version: 3.2.5 is not in the allowed range (,3.2).
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4:enforce (enforce-versions) on project javaocr-parent: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
and the configuration is 并且配置是
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<!--different rules for different issues-->
<!--3.3.x causes `java.lang.NoClassDefFoundError: org/eclipse/aether/spi/connector/Transfer$State` which is caused by certain maven versions, see https://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound for details-->
<version>(,3.3)</version>
<!--3.2.x causes `No implementation for org.eclipse.aether.connector.wagon.WagonConfigurator was bound.`-->
<version>(,3.2)</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
The .travis.yml
is .travis.yml
是
language: java
install:
- wget http://mirrors.ae-online.de/apache/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz && tar xf apache-maven-3.1.1-bin.tar.gz
- apache-maven-3.1.1/bin/mvn clean install
You're misunderstanding the role of the Enforcer Plugin : 您误解了Enforcer插件的作用:
The Enforcer plugin provides goals to control certain environmental constraints such as Maven version, JDK version and OS family along with many more standard rules and user created rules.
Enforcer插件提供了控制某些环境约束的目标,例如Maven版本,JDK版本和OS系列以及更多标准规则和用户创建的规则。
Its goal is not to do magic so that the configured rules are verified, but it is to fail the build when one of the rules is not verified. 它的目标不是做魔术,以便验证已配置的规则,而是在未验证其中一个规则时使构建失败。 Put another way, it checks the list of configured rules, so that the build cannot continue if one of those isn't verified.
换句话说,它会检查已配置规则的列表,因此,如果其中一个未经验证,构建将无法继续。 The reason is that if one of the pre-requisite for the build is not met, it is better to fail as early as possible.
原因是,如果未满足构建的先决条件之一,则最好尽早失败。
In your case, the requireMavenVersion
rule enforces that the build is done with a Maven version strictly lower than 3.2. 在您的情况下,
requireMavenVersion
规则会强制使用严格低于3.2的Maven版本来完成构建。 It will not spawn a new Maven instance if you're running the build with a Maven 3.2.5 so that the rule is verified; 如果您使用Maven 3.2.5运行构建,它将不会产生一个新的Maven实例,以便验证该规则。 which version should it use, and where would it get it?
它应该使用哪个版本,它将在哪里得到? Instead, it detects that the build is done with a Maven version that is disallowed, and fails accordingly.
而是,它检测到构建是使用不允许的Maven版本完成的,因此失败。 Since the Travis build is configured to use Maven 3.2.5 , it is expected to fail, and you need to install a Maven version lower than 3.2 for your Travis build.
由于Travis构建配置为使用Maven 3.2.5 ,因此预期会失败,因此您需要为Travis构建安装低于3.2的Maven版本。
To use a different Maven version, like 3.1.1, on Travis CI, you can have the following in .travis.yml
: 要在Travis CI上使用其他Maven版本(如3.1.1),可以在
.travis.yml
包含以下.travis.yml
:
before_install:
- wget http://mirrors.ae-online.de/apache/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz
- tar xf apache-maven-3.1.1-bin.tar.gz
- export M2_HOME=$PWD/apache-maven-3.1.1
- export PATH=$M2_HOME/bin:$PATH
install: /bin/true
script: mvn clean install
As a side-note, your current configuration of 附带说明一下,您当前的配置
<requireMavenVersion>
<version>(,3.3)</version>
<version>(,3.2)</version>
</requireMavenVersion>
is completely equivalent to 完全等同于
<requireMavenVersion>
<version>(,3.2)</version>
</requireMavenVersion>
The range (,3.2)
means that it matches version strictly lower than 3.2. 范围
(,3.2)
表示它与严格低于3.2的版本匹配。 Therefore, requiring that it is also strictly lower than 3.3 is redundant (since 3.2 is before 3.3). 因此,要求它也严格低于3.3是多余的(因为3.2在3.3之前)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.