Maven Parent POM

19,158

Solution 1

You have to deploy your project to an internal Maven repository. To do that, you first need to configure a Maven repository server (I recommend using Apache Archiva), and then point your pom.xml and settings.xml to the server: http://archiva.apache.org/docs/1.4-M3/userguide/deploy.html

After deploying it, you can point all the projects from your company to use that pom as parent pom. You can use the same strategy to create internal project dependencies. That goes very well in a continuous integration environment.

Solution 2

If you put this parent pom in a folder called android and projects that will use it in the same folder like this.

  • Android
  • pom.xml
  • android-project-1
    • pom.xml

The project pom.xml can then use the parent pom by placing this at the top of its pom.xml:

<parent>
    <groupId>parent.group</groupId>
    <artifactId>parent.artifact</artifactId>
    <version>${version.number}</version>
    <relativePath>../</relativePath>
</parent>

You could then extend this architecture in future like this:

  • Mobile
    • pom.xml
    • Android
      • pom.xml
      • android-project-1
      • android-project-2
    • iPhone
      • pom.xml
      • iphone-project-1

This lets you define common config for android projects, common config for iphone projects and common config for all mobile projects. And so on

Solution 3

For every child pom, place a reference to the parent pom.

<parent>
    <groupId>com.mycomp</groupId>
    <artifactId>parent-pom-android</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>relative/path/to/parent/pom</relativePath>
</parent>

relativePath is computed starting from the child pom

Solution 4

Packaging type should be pom instead of apk.

Share:
19,158
AndroidDev
Author by

AndroidDev

Updated on August 13, 2022

Comments

  • AndroidDev
    AndroidDev almost 2 years

    I am new to Maven and have recently installed nexus. Now I want to create a parent POM so that all my projects within my company can use this. This is my parent POM.

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
     http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>1.0.0</modelVersion>
        <groupId>com.mycomp</groupId>
        <artifactId>parent-pom-android</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <packaging>apk</packaging>
        <name>Android Parent POM</name>
    
        <repositories>
            <repository>
                <id>nexus-repo</id>
                <url>http://10.10.10.230:8081/nexus/content/groups/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>nexus-repo</id>
                <name>confiz-repo</name>
                <url>http://10.10.10.230:8081/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
     </project>
    

    Now where do I place this POM file so that my other POM files can inherit from it ?

  • AndroidDev
    AndroidDev over 11 years
    I have installed nexus and uploaded the parent-pom.xml to nexus. How can i point my projects pom to read the pom from the nexus repo ?
  • Gilberto Torrezan
    Gilberto Torrezan over 11 years
    You need to configure your pom.xml and settings.xml to use that repository. Some info here: support.sonatype.com/entries/…
  • Lee Meador
    Lee Meador over 11 years
    If the parent pom is in Nexus and the settings.xml is configured to use the in-house Nexus, there is no need for the relative path. The relative path is useful when you have several projects in version control that are stored together and have a parent pom they all use. Then the parent pom isn't in Nexus but is in the version control with the group of projects.
  • Robert
    Robert about 7 years
    Sounds like a chicken-or-the-egg problem to me. The parent pom defines custom repositories, but the clients have to get the parent pom from the repository.
  • Gilberto Torrezan
    Gilberto Torrezan about 7 years
    @Robert not really, the settings.xml file is local to your configuration.