maven - Maven 中是否有一种方法可以确保设置了属性

标签 maven maven-3 pom.xml

我刚刚找到了一个由不良属性值引起的困难的 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/

相关文章:

java - 有没有办法通过POM.xml修改classpath?

maven - 如何让 maven 只运行 JMeter 测试(没有其他生命周期)

java - 构建失败[错误] 15669

java - Maven 根本不会运行

java - 如何在test和main之间共享资源?

java - Buildnumber maven 插件返回 null

java - 使用 jgitflow 将 Artifact 部署到非默认的 nexus 服务器

java - 找不到 javax.transaction :jta: in maven

eclipse - 执行目标tomcat失败:deploy Error writing to server

java - 导入maven项目但父模块被禁用