【问题标题】:Maven Enforcer Plugin: Specify rules via command lineMaven Enforcer Plugin:通过命令行指定规则
【发布时间】:2017-10-06 11:12:09
【问题描述】:
我想通过命令行执行Maven Enforcer plugin。
我试过了:
mvn enforcer:enforce -Drules=[requireReleaseDeps]
mvn enforcer:enforce -Drules=requireReleaseDeps
我总是收到这个错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce (default-cli) on project lkww-util-app-wurm-admin-rs-api: The parameters 'rules' for goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce are missing or invalid -> [He
lp 1]
如何指定rules 参数?
【问题讨论】:
标签:
maven
command-line
maven-3
maven-plugin
maven-enforcer-plugin
【解决方案1】:
您也可以在 POM 的主要部分预先配置您的 <executions>,而不是使用配置文件,然后使用 <execution> 的 <id> 从命令行调用它们(有关此语法的更多信息,请参阅Guide to Configuring Plug-ins):
mvn enforcer:enforcer@my-execution-id
由于默认情况下enforce goal 中的任何<execution> 将目标绑定到validate 阶段,但是my-execution-id 执行也运行在普通mvn clean install 上。如果不需要,请使用 <skip>true</true> 配置执行并在命令行上覆盖它:
mvn enforcer:enforcer@my-execution-id -Denforcer.skip=false
这是否比在 POM 的主要部分和 <profiles> 中传播 maven-enforcer-plugin 配置更清楚是个人喜好问题。
【解决方案2】:
enforcer 插件不允许通过命令行参数选择/使用规则。
有一个open issue 反对这个插件,所以你可以投票给那个。
同时,如果您选择的规则可以分类为少数选择,那么您也许可以创建配置文件并将规则与配置文件关联,从而允许通过指定配置文件为选定的规则子集运行构建。在下面的示例中,有两个配置文件,每个配置文件都有不同的实施者规则:
<profiles>
<profile>
<id>EnforceBannedPlugins</id>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>enforce-banned-plugins</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedPlugins>
...
</bannedPlugins>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</profile>
<profile>
<id>EnforceMavenVersion</id>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>enforce-maven-version</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
...
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</profile>
</profiles>
当然,如果您在运行时指定强制执行规则的要求可以通过一些固定配置来满足,那么这只是一个运行程序。但是,如果要求支持任何可能的强制执行规则,那么您就不走运了,因为插件不支持。