没有设置属性时,使构建失败的简单方法是什么?

没有设置属性时,使构建失败的简单方法是什么?

问题描述:

如标题中所述,如果未在命令行中设置属性,如何以一种最简单的方式修改pom.xml以使其失败.

As stated in the title, how can I modify - in the simplest manner possible - a pom.xml in order to make it fails if a property is not set in the command line.

例如,当mvn clean package -Dfoo=bar成功时,mvn clean package将失败.

For example, mvn clean package will fail, when mvn clean package -Dfoo=bar will succeed.

我正在寻找类似<prerequisites/>

I'm looking for something like the <prerequisites/> tag in the pom.xml (except that <prerequisites/> only allow me to check the Maven version)...

您可以使用

You can use the requireProperty goal of the maven-enforcer-plugin to fail a build if a property is missing.

请注意,这仅需要设置属性,因此可以在pom的属性部分中进行设置.

Note this only requires that the property is set, so it could have been set in the pom's properties section.