Monday, 30 January 2017

Parent and Child POM.xml


We can maintain parent and child pom.xml files for better and clearer dependency management in larger sized projects.

All the dependencies in the parent pom will be available in child pom by default and child pom dependencies overrides if mismatch happens.

Note : Directory structure has no dependency over parent and child relation of pom files.

Folder 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>

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>



Adding a private/ multiple repositories into pom.xml

Now a days most of the companies are implementing utilities and converting them into jar files and maintaining in the company repositories (similar to maven repo which is private)

As part of the framework, we might need to use Maven and our Private repo for dependency management.
Here is the solution for the problem.

In pom.xml, add below code.
<repositories>
    <repository>
      <id>my-priavte-repo1</id>
      <name>My comapny private repositiy</name>
      <url>http://MyComapanyName.ProjectName.Extension</url>
    </repository>    
</repositories>

Then adding dependencies is similar to Maven.


That’s all.