【发布时间】:2011-12-08 18:54:58
【问题描述】:
我正在使用 Maven 3.0.3。如果有人运行包含“验证”阶段的 Maven 任务,我想确保定义了一个属性“tomcat.manager.url”,如果没有,则抛出错误。但是,如果有人没有运行包含验证的命令(例如 mvn test),我不想抛出任何错误。
我该怎么做?
谢谢,- 戴夫
【问题讨论】:
标签: maven maven-2 properties
我正在使用 Maven 3.0.3。如果有人运行包含“验证”阶段的 Maven 任务,我想确保定义了一个属性“tomcat.manager.url”,如果没有,则抛出错误。但是,如果有人没有运行包含验证的命令(例如 mvn test),我不想抛出任何错误。
我该怎么做?
谢谢,- 戴夫
【问题讨论】:
标签: maven maven-2 properties
您可以将强制插件 (docs) 设置为在“验证”阶段执行,并使用需要设置该插件的规则,配置如下所示:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>enforce-property</id>
<goals>
<goal>enforce</goal>
</goals>
<phase>verify</phase>
<configuration>
<rules>
<requireProperty>
<property>tomcat.manager.url</property>
<message>You must set a tomcat manager url</message>
</requireProperty>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
由于插件只会在验证阶段执行,因此除非您正在运行达到该阶段的构建,否则不会进行检查。
【讨论】: