What does the parent tag in Maven pom represent?

元气小坏坏 提交于 2019-11-30 02:39:44

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.

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 more similar like normal pom.xml except it 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>

As the name suggests, we can point out a parent pom.xml file for the current pom.xml file. Doing so, dependencies, properties, constants and many more defined at the parent pom.xml file also get merged with the current pom.xml (child pom.xml) file. Say you have a parent tag in your projects pom.xml that looks like below:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.8.RELEASE</version>
</parent>

Then maven reads that parent POM from your local repository (or from repository managers like sonatype, jfrog, etc that you have configured) and creates a Resultant POM by combining the parent POM and your module’s POM.

To see the combined result use the following mvn command:

mvn help:effective-pom  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!