Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative Path in Maven parent definition

Tags:

maven

In defining a parent artifact, do I need to include the in the child's pom? For example,

Is the <relativePath> optional or required?

<parent>
    <groupId>org.hibernate.tutorials</groupId>
    <artifactId>hibernate-tutorials</artifactId>
    <version>5.1.0.Final</version>
    <relativePath>../pom.xml</relativePath>
</parent>
like image 534
ling Avatar asked Feb 24 '16 17:02

ling


People also ask

What is parent relative path in Maven?

By default, Maven looks for the parent POM first at project's root, then the local repository, and lastly in the remote repository. If parent POM file is not located in any other place, then you can use code tag. This relative path shall be relative to project root.

What is the use of parent in Maven?

This POM is the common parent of all of the Maven components in the Apache Maven project. Most of its contents are pinning down version numbers of plugins. It does provide minimal dependencyManagement for plexus-component and plugin-tools annotations.

What is the difference between parent and dependency in Maven?

A dependency is libraries you need to get your code to compile. This can be your own code, or libraries such as Apache Commons. A parent contains information, but nothing to actually build, that is shared between a number of your projects.

What is groupId and artifactId in Maven?

groupId – a unique base name of the company or group that created the project. artifactId – a unique name of the project. version – a version of the project.


1 Answers

It is not required. From the docs:

relativePath: The relative path of the parent pom.xml file within the check out. If not specified, it defaults to ../pom.xml. [...]

This means that you can omit this element and it will default to exactly what you already have, i.e. Maven will look for the parent POM in ../pom.xml which is one directory up.

like image 171
Tunaki Avatar answered Sep 29 '22 10:09

Tunaki