Andy Feldman wrote:
> I guess you don't even need a custom property since each plugin tends to
> have one already. So a simpler property-based approach would just be:
> 
> <properties>
>   <enforcer.skip>${skipChecks}</enforcer.skip>
> </properties>
> 
> And maybe you'd also need <skipChecks>false</skipChecks> in your properties
> to provide a default for when skipChecks isn't specified on the command
> line. But like I said, I haven't tried this approach so you'd have to
> experiment and see if it works for you.

Thank you, Andy, for the suggestions.

My situation is unfortunately a bit more complex than that, as I have
*two* <execution>s of the maven-enforcer-plugin, only one of which
should be affected by -DskipChecks. The other simply uses the
<requireMavenVersion> rule, which IMHO shouldn't easily be disabled (but
should still respect -Denforcer.skip)

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <executions>
      <execution>
        <id>enforce-maven-version/id>
        <goals>
          <goal>enforce</goal>
        </goals>
        <configuration>
          <rules>
            <requireMavenVersion>
              <version>[3.6,4)</version>
            </requireMavenVersion>
          </rules>
       </configuration>
     </execution>
     <execution>
        <id>checks</id>
        <goals>
          <goal>enforce</goal>
        </goals>
        <configuration>
          <skip>$[skipChecks}</skip>
          <rules>
            <!-- further rules -->
          </rules>
        </configuration>
      </execution>
    </executions>
  </plugin>

I can't think of a way to use <properties> to get the desired behavior
in this case, at least not without resorting to profiles -- which I am
trying to avoid, as they seem to be frowned upon for this kind of stuff.

What I want is this:

  no property -> enforce-maven-version, checks

  -DskipChecks=false -> enforce-maven-version, checks

  -DskipChecks=true -> enforce-maven-version

  -Denforcer.skip=true -> no executions

  -Denforcer.skip=false, -DskipChecks=true -> enforce-maven-version,
checks (but possibly other checks predicated on skipChecks)

  etc.

In other words, -Denforcer.skip, being the more direct option, should
take precedence over -DskipChecks.

Any ideas?

Best wishes,

Andreas Sewe

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to