Maven2:如何确保 Maven 构建使用特定的插件版本? [英] Maven2: How to be sure Maven build is using a specific plugin version?

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

问题描述

我刚刚发现 Maven 插件管理听起来很奇怪.

I just found something that sounds weird with Maven plugin management.

在进行站点生成时,我想使用特定版本的 Maven 站点插件,以便使特定功能正常工作.假设我想使用这个插件的 2.0.1 版.

While working on the site generation I wanted to use a specific version of the maven site plugin in order to have a specific functionnalty working. Let's say I want to use version 2.0.1 of this plugin.

如果我使用 POM 的报告部分以使用以下命令生成我的项目站点:

If I use the reporting section of my POM in order to generate my project's site with the command:

mvn site

这很好用.我的意思是使用的插件版本是我想要的 2.0.1.这是我配置站点插件的 POM 的摘录:

this works well. I mean the plugin version used is 2.0.1 as I wanted. Here is an extract from my POM configuring the site plugin:

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>2.0.1</version>
        </plugin>
    </plugins>
</reporting>

现在,如果我希望我的网站在构建生命周期的特定阶段生成,比如准备包(和目标阶段),我会在该部分添加以下部分:

Now if I want my site to be generated during a specific phase of the build life cycle, let's say prepare-package (and goal stage), I add the following section in the section:

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>

        <executions>
            <execution>
                <phase>prepare-package</phase>
                <goals>
                    <goal>stage</goal>
                </goals>
            </execution>
        </executions>
     </plugin>
</plugins>

在这里,我坚持使用来自 Super POM 的 Maven 站点插件版本,即.2.0-beta-7.即使我尝试添加指定我真的想使用版本 2.0.1 的配置,它仍然使用 2.0-beta-7.我还尝试在该部分添加版本,因为报告部分中使用的配置也应该应用于构建部分.但这也不起作用.

And here I am stuck with the maven site plugin version coming from the Super POM, ie. 2.0-beta-7. Even if I try to add the configuration specifying I really want to use version 2.0.1 it still uses 2.0-beta-7. I also tried to add the version in the section because the config that is used in the reporting section is supposed to be applied to the build section also. But this does not work neither.

也许我错过了一些东西,如果我错了,请纠正我,但这看起来像是一个错误.Maven 方面是否需要修复构建过程中要使用的插件版本?

Maybe I missed something, and correct me if I am wrong but this looks like a bug. Is there a need on the Maven side to fix plugin's version to be used during the build process?

谢谢!

推荐答案

如果在 pom 中定义了 pluginManagement 部分,则可以声明用于任何插件的版本,这将覆盖从超级 POM 继承的版本

If you define a pluginManagement section in the pom, you can declare the versions used for any plugins, this will override the versions inherited from the super POM

例如:

<pluginManagement>
  <plugins>
    <plugin>
      <artifactId>maven-site-plugin</artifactId>
      <version>2.0.1</version>
    </plugin>       
  </plugins>
</pluginManagement>

您可以参考文档了解有关配置 pluginManagement 的一些背景知识.

You can refer to the documentation for some background on configuring pluginManagement.

这篇关于Maven2:如何确保 Maven 构建使用特定的插件版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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