Maven enforcer plugin missing or invalid rules

后端 未结 3 1480
Happy的楠姐
Happy的楠姐 2021-02-07 00:50

I am trying to setup the enforcer plugin for maven to enforce a minimum Java version. However, whenever I try to run mvn enforcer:enforce, I get:

相关标签:
3条回答
  • 2021-02-07 00:59

    I encountered this precise same error while trying to build vertx workshop project. As it turns out, the error is primarily an enforcer plugin version related issue. This following configuration solved it for me.

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-enforcer-plugin</artifactId>
      <version>3.0.0-M3</version><!--$NO-MVN-MAN-VER$-->
      <executions>
        <execution>
          <id>enforce-java</id>
          <phase>enforce</phase>
          <goals>
            <goal>enforce</goal>
          </goals>
          <configuration>
            <rules>
              <requireJavaVersion>
                <version>(1.8.0,)</version>
              </requireJavaVersion>
            </rules>
          </configuration>
        </execution>
      </executions>
    </plugin>
    
    0 讨论(0)
  • 2021-02-07 01:07

    In my case the problem was that I was putting the enforcer configuration inside the build part of a Maven profile which was not being built when I ran mvn validate. A simple mvn validate -P correctProfile fixed it for me. In the end I put it into the parent project of a multi-module application, set the transitive search of bytecode enforcer rule to true: <searchTransitive>true</searchTransitive> and verified that an incorrect dependency in a child project indeed causes a build failure.

    0 讨论(0)
  • 2021-02-07 01:19

    It may be that you are using invalid rule names. Check out the rules page. The rule names are case sensitive. Though this is not the case here.

    ---- Edit ----

    Note that the POM configuration has an execution ID of enforce-java and that execution is bound to the validate phase of the lifecycle. The command mvn enforcer:enforce is running a goal, not a phase in the lifecycle. The configuration you provided in the POM doesn't apply to the enforcer:enforce goal.

    There are two ways to make this work. Which one you choose depends on what you need.

    1. If you are just trying to test the enforcer plugin configuration without running the whole build, run mvn validate.
    2. If the requirement is that mvn enforcer:enforce works, then change the execution ID to default-cli.
    0 讨论(0)
提交回复
热议问题