Java Maven 执行器插件丢失或无效的规则
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24827194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven enforcer plugin missing or invalid rules
提问by X3no
I am trying to setup the enforcer plugin for maven to enforce a minimum Java version. However, whenever I try to run mvn enforcer:enforce
, I get:
我正在尝试为 maven 设置执行器插件以强制执行最低 Java 版本。但是,每当我尝试运行时mvn enforcer:enforce
,我都会得到:
The parameters 'rules' for goal org.apache.maven.plugins:maven-enforcer-plugin:1.3.1:enforce are missing or invalid
目标 org.apache.maven.plugins:maven-enforcer-plugin:1.3.1:enforce 的参数“规则”丢失或无效
Here is the relevant portion of my pom file:
这是我的 pom 文件的相关部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-java</id>
<phase>validate</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>(1.7.0-20,)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
I also tried replacing the <requireJavaVersion>
block with <alwaysPass/>
, in case something was invalid, but it still failed with the same error.
我也尝试用 替换<requireJavaVersion>
块<alwaysPass/>
,以防万一无效,但它仍然失败并出现相同的错误。
采纳答案by user944849
It may be that you are using invalid rule names. Check out the rulespage. The rule names are case sensitive. Though this is not the case here.
可能是您使用了无效的规则名称。查看规则页面。规则名称区分大小写。虽然这里不是这种情况。
---- Edit ----
- - 编辑 - -
Note that the POM configuration has an execution ID of enforce-java
and that execution is bound to the validate
phase of the lifecycle. The command mvn enforcer:enforce
is running a goal, not a phase in the lifecycle. The configuration you provided in the POM doesn't apply to the enforcer:enforce
goal.
请注意,POM 配置的执行 ID 为enforce-java
并且该执行绑定到validate
生命周期的阶段。该命令mvn enforcer:enforce
正在运行一个目标,而不是生命周期中的一个阶段。您在 POM 中提供的配置不适用于enforcer:enforce
目标。
There are two ways to make this work. Which one you choose depends on what you need.
有两种方法可以完成这项工作。你选择哪一个取决于你需要什么。
- If you are just trying to test the enforcer plugin configuration without running the whole build, run
mvn validate
. - If the requirement is that
mvn enforcer:enforce
works, then change the execution ID todefault-cli
.
- 如果您只是尝试在不运行整个构建的情况下测试执行器插件配置,请运行
mvn validate
. - 如果要求
mvn enforcer:enforce
有效,则将执行 ID 更改为default-cli
。
回答by Gautam
I encountered this precise same error while trying to build vertx workshop project. As it turns out, the error is primarily an enforcer plugin version related issue. This following configuration solved it for me.
我在尝试构建 vertx Workshop 项目时遇到了这个完全相同的错误。事实证明,该错误主要是与执行器插件版本相关的问题。以下配置为我解决了这个问题。
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.0.0-M3</version><!--$NO-MVN-MAN-VER$--> <executions> <execution> <id>enforce-java</id> <phase>enforce</phase> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requireJavaVersion> <version>(1.8.0,)</version> </requireJavaVersion> </rules> </configuration> </execution> </executions> </plugin>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.0.0-M3</version><!--$NO-MVN-MAN-VER$--> <executions> <execution> <id>enforce-java</id> <phase>enforce</phase> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requireJavaVersion> <version>(1.8.0,)</version> </requireJavaVersion> </rules> </configuration> </execution> </executions> </plugin>