问题描述:

(using Maven 3.0.3 on Mac with Java 7)

When I run mvn dependency:analyze-duplicate maven uses the version 2.1 (no matter if 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 have assumed, maven always falls back to the most recent version (even if not yet in the local repo), if no version is explicitly specified?

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

网友答案:

For some plugins Apache Maven has defined a default version in the one and only super-pom, which can be upgraded with a newer version of Maven. See the current trunk: 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>

In Maven-3.1 both the maven-dependency-plugin and maven-release-plugin have been upgraded. Previous releases still used 2.1 and 2.0 (in same order).

So these are the default if you haven't specify a version in your pom.xml or if you don't have a one.

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

网友答案:

The process of Resolving a Plugin's Version is described here.

In short Maven will use the first version found by this rules in this order:

  • version defined in the project's POM
  • version defined in the plugin registry (if enabled)
  • LATEST version metadata
  • RELEASE version metadata

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

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

相关阅读:
Top