Maven plugin inheritance configuration management strange behavior

I am using the pluginManagement element in the parent pom.xml to configure plugins for all its children. For example, I have the following configuration:

 <pluginManagement> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.4.3</version> <executions> <execution> <id>copy-artifacts</id> <phase>install</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>some/where/else</outputDirectory> <resources> <resource> <directory>some/another/resource</directory> </resource> </resources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>copy-dependencies</id> <phase>install</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>deps/dir</outputDirectory> </configuration> </execution> </executions> </plugin> </pluginManagement> 

The official documentation states that the plugin configured in pluginManagement should still be added to the plugins element in children's pumps. Indeed, if I remove this from child pom:

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

then maven-dependency-plugin stops firing on the install phase. However, this does not seem to affect some other plugins, namely the maven-resource-plugin . Even if I don’t have

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

in my child pom, its copy-resources target still fires at the install stage and does the work that it configured to execute.

Why is this behavior present? Is there a list of plugins that are always inherited, or maybe I missed something?

+7
source share
2 answers

The entire POM is not displayed; but given the behavior you describe is a can, war or ear, right? The default resource plugin for these packaging types. It includes execution that copies resources (as described by @maba).

Because the plugin definition is included in your child POM (even if you did not put it directly), Maven combines the execution defined in the <pluginManagement> section with the execution provided by Maven.

There is documentation that describes default life-cycle bindings by type of packaging. Note that the dependency plugin is not specified; but resources ; why are you observing the difference. Running with -X will show the execution of the plugins.

+6
source

Maven always copies the resources inside src/main/resources by default.

From the Maven Getting Started Guide :

A simple rule used by Maven is the following: any directories or files placed in the ${basedir}/src/main/resources are packaged into your JAR with the same structure, starting from the JAR base.

+1
source

All Articles