Maven2: How to be sure Maven build is using a specific plugin version?

萝らか妹 提交于 2021-01-27 06:49:48

问题


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

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.

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

mvn site

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>

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.

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?

Thanks!


回答1:


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

For example:

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

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




回答2:


I think you need to use the "pluginManagement" section to set the global version number of the plugin.



来源:https://stackoverflow.com/questions/1341776/maven2-how-to-be-sure-maven-build-is-using-a-specific-plugin-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!