我进行了构建设置,以便通过命令行传递变量:
mvn clean install -DsomeVariable=data
在我的 pom 中我有:
<someTag>${someVariable}</someTag>
这工作正常,但我想确定是否在命令行上未指定 someVariable,然后默认它以便我的脚本可以继续。
这可以在 Maven 中完成吗?
您可以在中指定默认属性值properties
POM 文件的部分:
<properties>
<someVariable>myVariable</someVariable>
</properties>
如果您想确保属性值是ALWAYS在命令行上提供,然后您可以使用 maven-enforcer-plugin。
这是一个显示如何强制系统属性存在的链接 ->http://maven.apache.org/enforcer/enforcer-rules/requireProperty.html
我将在此处逐字复制 XML,以防上述链接失效。
<project>
[...]
<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>
<configuration>
<rules>
<requireProperty>
<property>basedir</property>
<message>You must have a basedir!</message>
<regex>\d</regex>
<regexMessage>You must have a digit in your baseDir!</regexMessage>
</requireProperty>
<requireProperty>
<property>project.version</property>
<message>"Project version must be specified."</message>
<regex>(\d|-SNAPSHOT)$</regex>
<regexMessage>"Project version must end in a number or -SNAPSHOT."</regexMessage>
</requireProperty>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)