10

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>
sys463
  • 337
  • 2
  • 5
  • 18
  • `plugins` element is not closed. – Ortomala Lokni Nov 12 '18 at 19:41
  • Have you declared the plugins in the build->plugins section of your pom? – gjoranv Nov 12 '18 at 22:47
  • Thanks @OrtomalaLokni, seems like it was lost while creating a post. It's closed in my pom – sys463 Nov 13 '18 at 10:51
  • @gjoranv, no I have not. Does it make any sense, since I've declared in ``? – sys463 Nov 13 '18 at 10:53
  • It's easy to verify. Either, move the 'plugins' block directly under 'build' instead of 'pluginManagement'. Or just add the plugins inside 'build' without any version or config, which will then be "inherited" from pluginManagement. – gjoranv Nov 13 '18 at 11:23
  • @gjoranv Wow! Declaring `versions-maven-plugin` inside "build -> plugins" works well! But I still cannot understand why it doesn't work inside ``.... – sys463 Nov 13 '18 at 11:45
  • @sys463 To understand read [Maven: What is pluginManagement?](https://stackoverflow.com/questions/10483180/maven-what-is-pluginmanagement) – Ortomala Lokni Nov 13 '18 at 13:25
  • @sys463 Good to hear. I tried to distill this into an answer. – gjoranv Nov 13 '18 at 15:59

1 Answers1

11

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.

gjoranv
  • 4,376
  • 3
  • 21
  • 37