我有一个POM文件,其中包含一个属性(在“属性”部分下),该属性具有将其推入git时使用的IP值。
<device.ip>1.2.3.4</device.ip>
但是对于我的构建,我需要使用另一个IP值,因此当我开始在新分支上工作时,应该将其更改为所需的IP。
我希望能够在构建启动时检查变量值,并在变量值与我需要的值不同的情况下中止它。
也欢迎其他任何解决方案。
(我希望我的问题不会因为缺少代码而被降级-这里没有真正的代码可写。这种情况很容易解释)
谢谢您的建议。
答案 0 :(得分:2)
您可以使用支持此类检查的maven-enforcer-plugin。
requirePropery规则的用法如下。
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce-property</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireProperty>
<property>device.ip</property>
<message>You must set a device.ip property!</message>
<regex>.*\d.*</regex> <!-- Express the value you need. -->
<regexMessage>The device.ip property contain...</regexMessage>
</requireProperty>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
答案 1 :(得分:2)
我建议将您的项目分成模块。
这对我来说效果很好。