如何使用 Maven Enforcer 插件?
我想使用 Maven Enforcer 插件来检查我的路径上是否有重复的类。
我已经尝试了此处中的示例。
但是当我像这样运行它时:
mvn enforcer:enforce
我收到此错误:
执行目标失败 org.apache.maven.plugins:maven-enforcer-plugin:1.0.1:enforce 项目 datapopulator 上的(default-cli):参数“规则” 目标 org.apache.maven.plugins:maven-enforcer-plugin:1.0.1:enforce 是 缺失或无效
有没有办法正确使用它?
编辑 #1
如果将我的配置更改为:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<AlwaysPass />
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
会产生相同的错误。
I'd like to use the Maven Enforcer plugin to check to see if I have duplicate classes on my path.
I've tried the example from here.
But when I run it like this:
mvn enforcer:enforce
I get this error:
Failed to execute goal
org.apache.maven.plugins:maven-enforcer-plugin:1.0.1:enforce
(default-cli) on project datapopulator: The parameters 'rules' for
goal org.apache.maven.plugins:maven-enforcer-plugin:1.0.1:enforce are
missing or invalid
Is there a way to use this correctly?
EDIT #1
If changing my config to this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<AlwaysPass />
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
Produces the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的第一个版本不起作用的原因是执行标记内的插件配置和执行标记外的插件配置之间存在差异。仅当您的插件由完整 Maven 构建的特殊阶段触发时才会使用执行。
Maven 配置指南 对此进行了更好的解释:
The reason why your first version did not work is because there is a difference between a plug-in configuration inside the execution tag and a plug-in configuration outside the execution tag. The execution is only used when your plug-in is triggered by a special phase of the complete Maven build.
The Maven guide to configuration explains it better:
试试这个,将配置移到执行之外,这样它就不受生命周期阶段的约束。
现在,当您执行
mvn enforcer:enforce
时,它会从您的 pom.xml 中选择规则。Try this, moving the configuration outside executions, so it isn't bound to the life cycle phase.
Now when you do
mvn enforcer:enforce
, it picks the rules from your pom.xml.请参阅这些答案
您可以使用特殊的默认命令行执行 id,default-cli 调用它(请参阅 Maven文档),请参阅下面的示例。这至少适用于 3.1.1,引用的文章说它应该适用于 2.2.0+
但是,如果您使用以上 Maven 3.1.1(我可以确认)在 3.3.3 中与执行器 v 1.4.1 配合使用)您可以使用新的 @ 语法指定您希望的执行 id(请参阅 Maven JIRA 以及上面的答案);
例如,对于下面的示例,使用
Here's a snippet from my pom;
See these answers
You can use the special default command line execution id, default-cli to invoke it (see Maven Docs), see my example below. This works at least with 3.1.1 and the article cited says it should work with 2.2.0+
However if you are using above Maven 3.1.1 (I can confirm it works in 3.3.3 with enforcer v 1.4.1) you can specify the execution id you wish using the new @ syntax (see Maven JIRA and the answers above);
e.g. for the example below use
Here's a snippet from my pom;
我不知道为什么它不适用于执行中的配置,但这对我有用:
I don't know why it won't work with the config being in an execution, but this worked for me: