Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Parent POM

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 ?

like image 497
AndroidDev Avatar asked Jan 18 '13 14:01

AndroidDev


2 Answers

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

like image 174
cowls Avatar answered Oct 03 '22 01:10

cowls


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.

like image 24
Gilberto Torrezan Avatar answered Oct 03 '22 02:10

Gilberto Torrezan