Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the parent tag in Maven pom represent?

E.g.:

<parent>     <groupId>mycompany.trade.com</groupId>     <artifactId>mycompany.trade.</artifactId>     <version>1.1.1.0-SNAPSHOT</version> </parent> 

Does it mean that Maven will search for parent pom? If yes, where, in which order? May be in folder up 1 level? Or in local repository or in repo?

like image 716
user710818 Avatar asked Nov 06 '11 10:11

user710818


People also ask

What is parent tag in Maven POM?

Maven Basics. Maven parent POM (or super POM) is used to structure the project to avoid redundancies or duplicate configurations using inheritance between pom files. It helps in easy maintenance in long term.

What is parent POM and child POM?

A POM can be a parent POM and it will be inherited to all child POM. So all the dependencies which has been set in parent POM need not to set in child POM. But if any dependency jar has been configured in parent and child POM both with different version then the child POM�s dependency version is takes priority.

What is parent POM in Maven POM xml for spring?

Spring Boot Starter Parent is a starter project that provides the default configuration for spring-based applications. It is added as a parent in the pom. xml file. The spring-boot-starter-parent defines spring-boot-dependencies as its parent.

What is parent form in Maven POM xml for spring boot?

All Spring Boot projects use spring-boot-starter-parent as a parent in pom. xml file. Configuration: It allows us to maintain consistency of Java Version and other related properties. Dependency Management: It controls the versions of dependencies to avoid conflict.


2 Answers

Yes, maven reads the parent POM from your local repository (or proxies like nexus) and creates an 'effective POM' by merging the information from parent and module POM.

See also Introduction to the POM

One reason to use a parent is that you have a central place to store information about versions of artifacts, compiler-settings etc. that should be used in all modules.

like image 82
stacker Avatar answered Oct 02 '22 15:10

stacker


The common dependencies,Properties,constants etc can be definded in central parent project pom.xml

The main important thing is the parent project cannot be distributed and it looks quite similar to a regular "pom.xml" except that it also has a packaging tag

    <groupId>com.company.demo</groupId>     <artifactId>MavenInheritance</artifactId>     <version>0.0.1-SNAPSHOT</version>     <packaging>pom</packaging> 

The child now able to inherit this using

   <parent>         <groupId>com.company.demo</groupId>         <artifactId>MavenInheritance</artifactId>         <version>0.0.1-SNAPSHOT</version>     </parent> 
like image 30
Vino Avatar answered Oct 02 '22 16:10

Vino