Search code examples
mavenmaven-pluginmaven-enforcer-plugin

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? 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.


Solution

  • I've followed a simpler approach: evaluateBeanshell rule. Thanks to the Stephen Connolly answer, I've managed to find out where the "recursive" boolean was.

    <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.