What Is Pluginmanagement in Maven'S Pom.Xml

What is pluginManagement in Maven's pom.xml?

You still need to add

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

in your build, because pluginManagement is only a way to share the same plugin configuration across all your project modules.

From Maven documentation:

pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.

Difference between <plugins> and <pluginManagement> tag in Maven `pom.xml`

From Maven documentation:

pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.

You can look at a better answer

pluginManagement interferes with shade plugin

<pluginManagement> role is described in Maven documentation :

Plugin Management contains plugin elements in much the same way [than plugins], except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.

Its goal here in the project generated by the archetype is to set specified versions of default plugins (maven-clean-plugin, maven-jar-plugin, ...). Note that these default plugins do not appear in your POM <plugins> section, but they are declared implicitly (you can check it by running mvn help:effective-pom).

But adding a plugin to <pluginManagement> section does not make your project invoke that plugin. Here, you can just set configuration and the version of the plugin you want to use. To invoke the plugin, you should absolutely declare it in <plugins> section.

In some projects (most of time multi-module projects), you could see the plugin and its configuration declared in <pluginManagement> of parent POM, and then referenced on <plugins> section of modules needing invocation of that plugin : thus, you do not have to repeat the same configuration on each module.

<pluginManagement> is mostly used if you want to use POM inheritance. Otherwise, on simple projects, you can just declare them in <plugins> section. I've also seen some projects defining all configuration in <pluginManagement>, just to make <plugins> section shorter and more readable, like the following example. It's just a matter of taste.

<build>
<!-- pluginManagement section : set versions and configurations -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>

<!-- plugins section : plugins that are invoked when building the project -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>

You can also read more on StackOverflow : Maven : What is pluginManagement?

Plugin management in maven

You put the configuration into the parent into pluginManagement.

Either you specify the plugin (without configuration) in each module where you need it, or you use the skip parameter to activate/deactivate the plugin.

Is it possible to specify pluginManagement not in parent pom?

This is currently not possible. There's an open ticket in the Maven project to add this feature.

How most basic pom file get pluginManagement in Effective pom

all such versions are from super pom
http://maven.apache.org/ref/3.5.2/maven-model-builder/super-pom.html , pluginManagement should be copied to pom.xml and version are upgraded in pom.xml to latest versions.

Maven Plugin defined in Parent Pom sometimes does not trigger in Child without declaration

The section <pluginManagement> is used to share plugin configurations between this project and child projects. Plugins are only executed if they are defined in <plugins>. See this answer for more information.

However, some plugins don't need to be defined in <plugins>. This applies to plugins of the built-in lifecycle binding like maven-jar-plugin, maven-resource-plugin and maven-compiler-plugin.



Related Topics



Leave a reply



Submit