Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 310
reef Avatar asked Feb 28 '23 09:02

reef


2 Answers

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.

like image 116
Rich Seller Avatar answered Apr 09 '23 23:04

Rich Seller


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

like image 25
krosenvold Avatar answered Apr 09 '23 21:04

krosenvold