Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - Parent Pom - Child Inheritance

Tags:

I am attempting to make a maven parent pom setup where I don't have to declare any plugin information in my child pom, everything is taken from the parent pom.

I essentially have it working where I've put all my plugins with there configurations in to the parent pom. Then in the child poms I have to declare the plugin still, but without the version and configuration information.

I don't want to have to declare the plugin in the child at all. This way I can add new features (such as pmd, freebugs, etc) to my parent pom and all my projects now have them working. How can I accomplish this?

Parent Pom

<pluginManagement>     <plugins>         <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-scm-plugin</artifactId>             <version>1.0</version>             <inherited>true</inherited>             <configuration>                 <providerImplementations>                     <cvs>cvs_native</cvs>                 </providerImplementations>                 <systemProperties>                     <property>                         <name>maven.scm.perforce.clientspec.name</name>                         <value>${perforceClientSpec}</value>                     </property>                 </systemProperties>             </configuration>         </plugin> 

Child Pom still needs this but I don't want to have to do this if I can avoid it:

<plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-scm-plugin</artifactId> </plugin> 
like image 347
Bellini Avatar asked Feb 28 '12 07:02

Bellini


People also ask

What do child POMs inherit from the parent pom?

Now child POM need to refer the parent POM using parent tag and specifying groupId/artifactId/version attributes. This pom file will inherit all properties and dependencies from parent POM and additionally can include extra sub-project specific dependencies as well.

What is parent and child pom in Maven?

A parent pom. xml file (or super POM) in Maven is used to structure the project in order to avoid redundancies and duplicate configurations by using an inheritance between different pom. xml files. If any dependency or properties are configured in both - parent and child - pom.

What is the Maven order of inheritance?

The Maven's order of inheritance is: Settings. CLI parameters. Parent POM.

Are Maven properties inherited?

Maven supports project inheritance. You can create a parent project that contains properties child projects have in common, and child projects inherit those properties from the parent project.


1 Answers

<pluginManagement> section 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 (so you have to explicitly specify them, as you indicated). See more here.

If you want to avoid this, you can put this information into <build> section like this:

<build>   <plugins>     <plugin>       <groupId>org.apache.maven.plugins</groupId>       <artifactId>maven-scm-plugin</artifactId>       <version>1.0</version>       <configuration>         <...>       </configuration>       <executions>         <...>       </executions>     </plugin>   </plugins> </build> 
like image 185
Andrew Logvinov Avatar answered Dec 30 '22 06:12

Andrew Logvinov