Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struggling with Maven parent/child plugin configuration inheritance

I'm trying to write a parent pom, and I have a plugin defined, but I need to change the config for all inherited instances. So, I can put some configuration in the <pluginManagement> definition, and I can override it in the <plugin>, but how do I get the children to default back to the <pluginManagement> version?

<build>     <pluginManagement>         <plugins>             <plugin>                 <groupId>org.apache.maven.plugins</groupId>                 <artifactId>maven-checkstyle-plugin</artifactId>                 <version>2.9.1</version>                 <executions...>                 <configuration>                     <configLocation>                         (used by all children)                     </configLocation>                 </configuration>             </plugin>         </plugins>     </pluginManagement>     <plugins>         <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-checkstyle-plugin</artifactId>             <configuration>                 <configLocation>                     (unique to the parent)                 </configLocation>             </configuration>         </plugin>     </plugins> <build> 

So, what happens is the children continue to show the parent's config.

like image 266
end-user Avatar asked Feb 01 '13 14:02

end-user


People also ask

Does child POM inherit plugins?

Plugins declared outside of <pluginManagement> are inherited by child POMs, by default. Their settings can be overridden by each child if desired.

How do you override plugin in child pom?

Overriding configurations from a parent pom can be done by adding the combine. self="override" attribute to the element in your pom. It appears that for Maven2. 2.1 if you do this in a profile it doesn't merge with plugins defined in parent profiles but overrides them.

What is the difference between plugin and pluginManagement tags?

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.


1 Answers

Ok, I think I have it. The answer, in my case, relates to what you specified - I did need the tag. However the solution was in the tag; by binding it to a non-phase, it does execute. This I knew. What I discovered is that the had to match in order for it to override. Thus, the config never gets parsed and doesn't matter.

<build>     <pluginManagement>         <plugins>             <plugin>                 <!-- Main declaration of the plugin -->                 <groupId>org.apache.maven.plugins</groupId>                 <artifactId>maven-checkstyle-plugin</artifactId>                 <version>2.9.1</version>                 <executions>                     <execution>                         <!--This must be named-->                         <id>checkstyle</id>                         <phase>compile</phase>                         <goals>                             <goal>check</goal>                         </goals>                     </execution>                 </executions>                 <configuration...>             </plugin>         </plugins>     </pluginManagement>     <plugins>         <plugin>             <!-- Uses the default config -->             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-checkstyle-plugin</artifactId>             <inherited>false</inherited>             <executions>                 <execution>                     <!--This matches and thus overrides-->                     <id>checkstyle</id>                     <phase>none</phase>                 </execution>             </executions>         </plugin>     </plugins> </build> 
like image 136
end-user Avatar answered Oct 20 '22 04:10

end-user