我刚刚找到了一个由不良属性值引起的困难的 Maven 问题。
该属性是测试运行时使用的备用 JVM 的路径。
我想通过检测路径是否有效来使 maven 尽早失败。
什么可能是实现这一目标的方法?
我打算深入研究 antrun,看看是否有办法让它先运行,以便它可以检查,但这似乎有点矫枉过正。
问题 : 我怎样才能干净、简单地做到这一点?
最佳答案
您可以使用 Enforcer Maven Plugin和它的 Require Property规则,您可以在其中强制存在某个属性,可选择使用某个值(匹配的正则表达式),否则构建失败。
This rule can enforce that a declared property is set and optionally evaluate it against a regular expression.
一个简单的片段是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-property</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireProperty>
<property>basedir</property>
<message>You must set a basedir property!</message>
<regex>.*\d.*</regex>
<regexMessage>The basedir property must contain at least one digit.</regexMessage>
</requireProperty>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
关于maven - Maven 中是否有一种方法可以确保设置了属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36220448/