How does Maven determine which version of the plugin to use for plugins used from the command line?

(using Maven 3.0.3 on Mac with Java 7)

When I run mvn dependency:analyze-duplicate , maven uses version 2.1 (regardless of whether 2.8 is available in my local repo or not) of the plugin and complains:

 [ERROR] Could not find goal 'analyze-duplicate' in plugin org.apache.maven.plugins:maven-dependency-plugin:2.1 among available goals unpack-dependencies,.... 

When I run it as mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:analyze , it works fine.

I would suggest that maven always reverts to the latest version (even if it is not already in the local repo) if no version is explicitly specified?

What am I missing? Thank you all for your time to respond.

+6
source share
2 answers

For some plugins, Apache Maven defined a default version in one and only super-pom, which can be updated with a newer version of Maven. See the current line: https://git-wip-us.apache.org/repos/asf?p=maven.git;a=blob_plain;f=maven-model-builder/src/main/resources/org/apache /maven/model/pom-4.0.0.xml

 <pluginManagement> <!-- NOTE: These plugins will be removed from future versions of the super POM --> <!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) --> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-5</version> </plugin> <plugin> <artifactId>maven-dependency-plugin</artifactId> <version>2.8</version> </plugin> <plugin> <artifactId>maven-release-plugin</artifactId> <version>2.3.2</version> </plugin> </plugins> </pluginManagement> 

Maven-3.1 has updated the maven-dependency-plugin and maven-release-plugin. Previous releases are still using 2.1 and 2.0 (in the same order).

So, this is the default if you did not specify a version in your pom.xml or if you do not have one.

To see effective pom, do mvn org.apache.maven.plugins:maven-help-plugin:2.2:effective-pom or help:effective-pom , but then you rely on the version in super-pom again.

+7
source

The process of resolving the plugin version is described here .

In short, Maven will use the first version found by these rules in the following order:

  • version defined in the POM project
  • defined in the plugin registry (if enabled)
  • LAST version metadata
  • RELEASE version metadata

So, look in your POM project (or parent pom) if you specified a version for this plugin.

Update . As for your problem, the reason is that version 2.1 for maven-dependency-plugin is listed in the pluginManagement maven Super POM section. Your pom project inherits these settings, and therefore version 2.1 is used by default (Upvote is the answer by @Robert Scholte, who pointed this first!)

+3
source

Source: https://habr.com/ru/post/945604/


All Articles