mavenmaven-3maven-enforcer-pluginversions-maven-plugin

"Project does not define required minimum version of Maven" with versions-maven-plugin 2.7


I'm facing the following error executing mvn versions:display-plugin-updates. Basing on this discussion, that was fixed in 2.6, but I'm using 2.7 (tried with 2.6 but with no success).

[ERROR] Project does not define required minimum version of Maven.
[ERROR] Update the pom.xml to contain maven-enforcer-plugin to
[ERROR] force the Maven version which is needed to build this project.
[ERROR] See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html
[ERROR] Using the minimum version of Maven: 3.0.5

Here's my <pluginManager> plugins:

<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-enforcer-plugin</artifactId>
      <version>3.0.0-M2</version>
      <executions>
        <execution>
          <id>enforce-versions</id>
          <goals>
            <goal>enforce</goal>
          </goals>
          <configuration>
            <rules>
              <requireMavenVersion>
                <version>3.5.4</version>
              </requireMavenVersion>
            </rules>
          </configuration>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>versions-maven-plugin</artifactId>
      <version>2.7</version>
      <configuration>
        <generateBackupPoms>false</generateBackupPoms>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement>

Solution

  • Even if you have pluginManagement for a given plugin, you still need to declare the plugin in your pom's build->plugins section for the configuration to take effect. While some plugins, e.g. maven-compiler-plugin are added to the project by default, this is clearly not the case for maven-enforcer-plugin (as shown by your experiment).

    I'm not sure if there is a list of plugins that don't need to be explicitly added, but I assume it's the most common ones like maven-surefire-plugin and maven-clean-plugin.