微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

理解maven的parent标签里面的relativePath

经常看到用Spring Initializr简历spring boot项目,生成的pom.xml包含如下parent:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

也会看到一些maven module项目包含下面relativePath形式:

    <parent>
        <artifactId>admin</artifactId>
        <groupId>org.example</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

也有不写relativePath的,直接如下:

    <parent>
        <artifactId>admin</artifactId>
        <groupId>org.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

参考官方文档发现,relativePath是与从哪里继承相关联的,认③什么都不写等同于②,像①那种是不依赖本地parent pom,直接从reposity拉取,

Maven looks for the parent pom first in the reactor of currently building projects, then in this location on the filesystem, then the local repository, and lastly in the remote repo.

寻找parent pom优先级:本地项目>文件系统>本地库>远程库,而springboot认都是直接从远程库拉取的。

参考文档:

Understanding Maven’s “relativePath” Tag for a Parent POM:https://www.baeldung.com/maven-relativepath

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐