27

So, I'm trying to use the latest version of some plugins. Earlier I've used the prerequisites-tag but lots of resources (example) say that it should be considered deprecated and that the maven-enforcer-plugin should be used instead. this is my configuration:

<plugin>
  <inherited>true</inherited>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>1.3.1</version>
  <executions>
    <execution>
      <id>enforce-maven-3</id>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requireMavenVersion>
            <version>3.0.4</version>
          </requireMavenVersion>
        </rules>
        <fail>true</fail>
      </configuration>
    </execution>
  </executions>
</plugin>

However, when I run mvn versions:display-plugin-updates I still get this text:

[ERROR] Project does not define required minimum version of Maven.
[ERROR] Update the pom.xml to contain
[ERROR]     <prerequisites>
[ERROR]       <maven>3.0</maven>
[ERROR]     </prerequisites>
[INFO]
[INFO] Require Maven 2.0.6 to use the following plugin updates:
[INFO]   maven-jar-plugin ................................................ 2.4
[INFO]   maven-shade-plugin ............................................ 1.7.1
[INFO]
[INFO] Require Maven 2.2.1 to use the following plugin updates:
[INFO]   maven-jar-plugin ................................................ 2.6
[INFO]
[INFO] Require Maven 3.0 to use the following plugin updates:
[INFO]   maven-shade-plugin .............................................. 2.3

Using the prerequisites-tag instead works.

Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
Richo
  • 751
  • 7
  • 17

3 Answers3

12

It seems like this issue has been reported here (credits go to Aleksandr M for finding this).

Apparently, the display-dependency-updates goal relies on the prerequisites element to find out the Maven version required by the current project and totally ignores the enforcer-plugin, even though the prerequisites-tag should not be used normally, it is required in order to get the dependency plugin to behave as expected.

Community
  • 1
  • 1
Richo
  • 751
  • 7
  • 17
  • When you write plugins, you often have other plugins as dependencies. Prerequisites tag was done to ensure plugins know what version given project requires - and in some cases do NOT run. Enforcer is for non-plugin projects, AFAI understand. – LAFK 4Monica_banAI_modStrike Apr 11 '16 at 06:53
  • 2
    The bug can now be found at https://github.com/mojohaus/versions-maven-plugin/issues/48 – davidwebster48 Feb 27 '17 at 00:46
  • 1
    The bug has been fixed in 2.6 unfortunately it has not been released yet so only snapshots are available in some repositories: https://github.com/mojohaus/versions-maven-plugin/issues/269 (Release 2.6 issue) – ST-DDT Jul 24 '18 at 14:50
10

To avoid this message I use last version of versions-maven-plugin

mvn org.codehaus.mojo:versions-maven-plugin:2.7:display-plugin-updates

Note that it still requires either use of maven-enforcer-plugin for all but maven-plugin projects, or use of prerequisites tag for projects with maven-plugin packaging.

scrutari
  • 1,378
  • 2
  • 17
  • 33
Radio Rogal
  • 462
  • 4
  • 9
  • Worked for me too, but only on a parent pom that defines a maven-enforcer-plugin configuration either in build/pluginManagement or in build/plugins. It still complains that a project using that parent pom does not "define required minimum version of Maven". It seems to be using the POM as written and not the effective POM. – AbVog Aug 07 '19 at 15:32
-2

The prerequisites is deprecated for Maven 3.X:

http://jira.codehaus.org/browse/MNG-4840 http://jira.codehaus.org/browse/MNG-5297

Furthermore if you call

 mvn versions:display-plugin-updates

you are not starting a life cycle whereas the configuration of your maven-enforcer-plugin is bound to the life cycle.

Furthermore you should pin all versions of the plugins you are using in your build.

And one very important things (excerpt from the FAQ):

The prerequisites tag was designed to be used by tools like plugins. It will work for regular projects, but it isn't inherited to their children. If it is set in a parent reactor, then Maven will do the check. However if one of the children are built, the check is not performed. The enforcer plugin is designed to allow centralized control over the build environment from a single "super-pom", and to allow greater flexibility in version specification by supporting ranges.

This means only if your developing plugins the prerequisites does make a limited sense better to use the maven-enforcer-plugin path. For usual development project use the maven-enforcer-plugin configuration way to force particular Maven versions.

To stay informed about plugin update i can recommend to subscribe to the Announcment mailing list or if you like to get a good overview see the plugins page.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Yes I know, my issue is that maven-enforcer-plugin (which replaces prerequisites) doesn't work – Richo Mar 31 '15 at 07:30
  • 2
    when I run mvn versions:display-plugin-updates I still get this text , see my original post. Also see Aleksandr M, he has identified the problem – Richo Apr 02 '15 at 08:57