Maven如何解析插件版本? [英] How does Maven resolve plugin versions?

查看:94
本文介绍了Maven如何解析插件版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读文档并仍然对于Maven如何决定要下载的插件版本感到困惑.

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. 一个空的本地存储库
  2. 默认设置.xml
  3. 运行一个简单的maven命令.例如,maven-archetype-quickstartmvn archetype:generate
  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.

运行命令后,Maven要做的第一件事就是下载一堆插件.

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

Maven正在下载的某些插件包括:

Some of the plugins Maven is downloading include:

  • maven-clean-plugin-2.4.1
  • maven-install-plugin-2.3.1
  • maven-deploy-plugin-2.5

为什么使用这些版本?

这些插件的最新版本是:

The most recent version of these plugins are:

  • maven-clean-plugin-2.5
  • maven-install-plugin-2.5.1
  • maven-deploy-plugin-2.8.1

我查看了我并不是一定要强迫Maven使用这些插件的不同版本,我只是想了解为什么它会解决这些版本.

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.

我正在使用Apache Maven 3.0.3

I'm using Apache Maven 3.0.3

推荐答案

Maven在 META-INF/plexus/components.xml 中定义了3个生命周期:

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

1.默认生命周期

定义了默认生命周期,而没有任何关联的插件.在 META-INF/plexus/default-bindings.xml

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

例如用于jar包装的插件绑定

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.清洁生命周期 干净的生命周期是直接通过其插件绑定定义的.

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.网站生命周期 网站生命周期是直接通过其插件绑定定义的.

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

代替

mvn clean:clean

这篇关于Maven如何解析插件版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆