理解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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM