Maven Parent POM

I am new to Maven and recently made a connection. Now I want to create a parent POM so that all my projects in 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 put this POM file so that my other POM files can inherit it?

+4
source share
4 answers

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

After deployment, you can specify all projects from your company to use this pom as the parent pom. You can use the same strategy to create internal project dependencies. This works very well in a continuous integration environment.

+3
source

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

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

The pom.xml project can then use the parent pom by placing it at the beginning of pom.xml:

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

You can then expand this architecture in the future as follows:

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

This allows you to define a common configuration for Android projects, a common configuration for iphone projects, and a common configuration for all mobile projects. And so on

+10
source

For each child pom, put a link 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 computed starting at child pom

+1
source

The type of packaging should be pom instead of apk .

+1
source

All Articles