简体   繁体   English

如何在丢失的标志上使Maven构建失败

[英]How to fail a Maven build on a missing flag

Is there a way to fail if the flag "-N" (--non-recursive) isn't present? 如果不存在标志“ -N”(-非递归),是否有失败的方法? I'm trying to accomplish something like this: 我正在尝试完成这样的事情:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <configuration>
        <rules>
            <requireProperty>
                <property>-N</property>
                <message>Missing --non-recursive flag</message>
            </requireProperty>
        </rules>
    </configuration>
</plugin>

This enforcement policy is in a profile. 此实施策略在配置文件中。 If there's a way to activate --non-recursive flag within a profile it would be ok. 如果有一种方法可以激活配置文件中的--non-recursive标志,那就没问题了。

You could write a custom enforcer rule that checks the MavenSession and ensures that the reactor projects list contains one and only one project. 您可以编写一个自定义MavenSession实施器规则,以检查MavenSession并确保反应堆项目列表仅包含一个项目。 That does not guarantee that you have been invoked with -N but it is just as effective for what you want. 那不能保证您已经用-N调用了它,但是对于您想要的东西同样有效。

I've followed a simpler approach: evaluateBeanshell rule. 我遵循了一种更简单的方法:valuateBeanshell规则。 Thanks to the Stephen Connolly answer, I've managed to find out where the "recursive" boolean was. 多亏了Stephen Connolly的回答,我设法找到了“递归”布尔值在哪里。

<plugin>
    <artifactId>maven-enforcer-plugin</artifactId>
    <executions>
        <execution>
            <id>require non recursive flag</id>
            <phase>validate</phase>
            <goals>
                <goal>enforce</goal>
            </goals>
            <configuration>
                <rules>
                    <evaluateBeanshell>
                        <condition>false == ${session.request.recursive}</condition>
                        <message>Non-recursive flag is missing</message>
                    </evaluateBeanshell>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

I think it works in maven 3 only. 我认为它仅适用于Maven 3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM