Justin
Justin

Reputation: 6251

How does Maven resolve plugin versions?

I'm reading the docs and still confused as to how Maven is deciding which versions of plugins to download.

For example, consider this simple scenario:

  1. an empty local repository
  2. a default settings.xml
  3. run a simple maven command. for example, mvn archetype:generate for the maven-archetype-quickstart as described in the Maven in 5 Minutes doc.

After running the command, the first thing Maven does is download a bunch of plugins.

Some of the plugins Maven is downloading include:

Why those versions?

The most recent version of these plugins are:

I looked at the LATEST version metadata for maven-clean-plugin and it's 2.5

It's not that I necessarily want to force Maven to use different versions of these plugins, I just want to understand WHY it's resolving to those versions.

I'm using Apache Maven 3.0.3

Upvotes: 25

Views: 10106

Answers (3)

Ashay Batwal
Ashay Batwal

Reputation: 5613

Maven defines 3 lifecycles in META-INF/plexus/components.xml:

1. Default Lifecycle

Default lifecycle are defined without any associated plugin. Plugin bindings for these lifecycles are defined separately for every packaging in META-INF/plexus/default-bindings.xml

e.g. Plugin bindings for jar packaging

<phases>
  <process-resources>
    org.apache.maven.plugins:maven-resources-plugin:2.6:resources
  </process-resources>
  <compile>
    org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile
  </compile>
  <process-test-resources>
    org.apache.maven.plugins:maven-resources-plugin:2.6:testResources
  </process-test-resources>
  <test-compile>
    org.apache.maven.plugins:maven-compiler-plugin:2.5.1:testCompile
  </test-compile>
  <test>
    org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
  </test>
  <package>
    org.apache.maven.plugins:maven-jar-plugin:2.4:jar
  </package>
  <install>
    org.apache.maven.plugins:maven-install-plugin:2.4:install
  </install>
  <deploy>
    org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
  </deploy>
</phases>

2. Clean Lifecycle clean lifecycle is defined directly with its plugin bindings.

<phases>
  <phase>pre-clean</phase>
  <phase>clean</phase>
  <phase>post-clean</phase>
</phases>
<default-phases>
  <clean>
    org.apache.maven.plugins:maven-clean-plugin:2.5:clean
  </clean>
</default-phases>

3. Site Lifecycle Site lifecycle is defined directly with its plugin bindings.

<phases>
  <phase>pre-site</phase>
  <phase>site</phase>
  <phase>post-site</phase>
  <phase>site-deploy</phase>
</phases>
<default-phases>
  <site>
    org.apache.maven.plugins:maven-site-plugin:3.3:site
  </site>
  <site-deploy>
    org.apache.maven.plugins:maven-site-plugin:3.3:deploy
  </site-deploy>
</default-phases>

If you want to override these default plugin version you can do it from command prompt as follows

mvn org.apache.maven.plugins:maven-clean-plugin:2.0:clean

instead of

mvn clean:clean

Upvotes: 17

yuranos
yuranos

Reputation: 9675

It becomes quite clear if you use -X option when building your projects. Please, check my answer in another thread: https://stackoverflow.com/a/48874533/4470135

Upvotes: 0

mkleint
mkleint

Reputation: 2321

Every version of Maven binaries has certain versions of plugin versions hardcoded. That's to make a somewhat reproducible build in the cases when user doesn't provide his own version information. Which you are encouraged to do and once you populate <pluginManagement> section with the plugin versions of your choice, the build will start using it.

Upvotes: 7

Related Questions