Home  >  Maven

Parent POM and Child POM Example

By Arvind Rai, August 20, 2013
A POM can be a parent POM and it will be inherited to all child POM. So all the dependencies which has been set in parent POM need not to set in child POM. But if any dependency jar has been configured in parent and child POM both with different version then the child POMís dependency version is takes priority. The minimum requirement of as POM is

1. modelVersion
2. groupId
3. artifactId
4. version

Now we will define parent and child POM . Child POM can have the configuration according to the directory structure of parent and child folder. Find a sample directory structure.

Directory Structure
|commonapp
|  -----pom.xml
|springapp
| ------pom.xml
 


Parent pom.xml
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.concretepage.app</groupId>
  <artifactId>commonapp</artifactId>
  <version> 1.0-SNAPSHOT</version>
</project>
 
Now the child POM will as given below.

Child pom.xml
<project>
  <parent>
    <groupId>com.concretepage.app</groupId>
    <artifactId>commonapp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../commonapp/pom.xml</relativePath>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>springapp</artifactId>
</project>

 
Parent referred in child POM differently according the parent and child project structure.
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us