我正在设置一个maven构建,并且需要在命令行上将目标服务器指定为一个属性(然后使用该属性来选择适当的配置文件),例如
mvn -Denv=test
如果没有设置属性,我希望构建失败--这可能吗?
是的,我是Maven的新手。
编辑:我见过this link,这似乎暗示这是不可能的,但不确定它是不是最新的。
发布于 2009-04-10 23:47:14
每个人都很亲近,但在enforcer中有一条规则,专门检查属性,不需要ant或时髦的配置文件:http://maven.apache.org/enforcer/enforcer-rules/requireProperty.html
该规则还可以检查属性的值。
发布于 2009-01-12 00:20:21
也许你可以使用这样的变通方法:在Maven中,如果某个属性没有设置,你可以激活一个配置文件:
<project>
...
<profiles>
<profile>
<id>failure_profile</id>
<activation>
<property>
<name>!env</name>
</property>
</activation>
</profile>
</profiles>
</project>
然后你应该强制这个配置文件总是失败,例如使用maven-enforcer-plugin:
<profile>
<id>failure_profile</id>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<AlwaysFail/>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
如果你不提供-Denv构建将会失败:
[INFO] [enforcer:enforce {execution: enforce}]
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.AlwaysFail failed with message:
Always fails!
[INFO] ---------------------------------------------------------
[ERROR] BUILD ERROR
嗯,它比Ant冗长得多,但纯粹是Maven :)
发布于 2009-01-08 21:12:37
我的第一个倾向是创建一个配置文件,该配置文件在env属性未设置时处于活动状态,并以某种方式使其失败。也许你可以写一个Maven插件来测试这个属性,如果它不存在就会失败?
或者,您可以使用一个非常小的ant-build脚本来测试它。
https://stackoverflow.com/questions/425198
复制相似问题