How to fail a Maven build on a missing flag

430 views Asked by At

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.

2

There are 2 answers

0
joao cenoura On BEST ANSWER

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.

0
Stephen Connolly On

You could write a custom enforcer rule that checks the MavenSession and ensures that the reactor projects list contains one and only one project. That does not guarantee that you have been invoked with -N but it is just as effective for what you want.