14
Aug

pom.xml parent/child setup

pom.xml parent/child setup
===========================

1. Create a Maven project with following pom.xml settings
==========================================================

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.parent.project</groupId>
	<artifactId>example</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<junit.version>3.8.1</junit.version>
		<spring.version>4.2.3.RELEASE</spring.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>${junit.version}</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>
	</dependencies>
</project>

2. Update parent pom.xml with following entries (already configured above):
===========================================================================
	<packaging>pom</packaging>

3. Create a child project which refers above parent project
============================================================

<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/xsd/maven-4.0.0.xsd">
	<parent>
		<groupId>com.parent.project</groupId>  <!--  This is how parent pom.xml is inherited to child project -->
		<artifactId>example</artifactId>       <!--  This is how parent pom.xml is inherited to child project -->
		<version>0.0.1-SNAPSHOT</version>      <!--  This is how parent pom.xml is inherited to child project -->
	</parent>

	<modelVersion>4.0.0</modelVersion>
	<groupId>com.parent.project</groupId>   <!--  This is same as parent pom.xml -->
	<artifactId>childProject</artifactId>   <!--  This is same as parent pom.xml -->
	<version>0.0.1-SNAPSHOT</version>       <!--  This is same as parent pom.xml -->
</project>


4. Update child project’s pom.xml file :
========================================
update child pom
goto build path and check it’s libraries in Java Build Path. You will see all parent’s dependencies there.