Maven parent.relativePath 說明

這裏日記一下 關於Maven非常基礎的問題: Maven parent.relativePath 的意思,很多人網上搜索 類似下面pom.xml中的問題 ,文件中的

<relativePath /> <!-- lookup parent from repository  --> 

是什麼意思?

    <parent>
        <groupId>com.middol</groupId>
        <artifactId>webbase-dependency-management</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

網上大多數回到如下:

設定一個空值將始終從倉庫中獲取,不從本地路徑獲取,如<relativePath />
Maven parent.relativePath
默認值爲../pom.xml
查找順序:relativePath元素中的地址–本地倉庫–遠程倉庫

部分 Java 菜鳥或是一部分老鳥竟然也懵逼
答案第一行 :

設定一個空值將始終從倉庫中獲取,不從本地路徑獲取,如<relativePath />  

然後又開始問 : 倉庫 是哪一個倉庫 !?

我就納悶了搜什麼百度,自己測試一下不就好了嗎,另外直接點擊進去看原生說明啊,下面是 xml 原生英文解釋:

      <xs:element name="relativePath" minOccurs="0" type="xs:string" default="../pom.xml">
        <xs:annotation>
          <xs:documentation source="version">4.0.0</xs:documentation>
          <xs:documentation source="description">
            The relative path of the parent &lt;code&gt;pom.xml&lt;/code&gt; file within the check out.
            The default value is &lt;code&gt;../pom.xml&lt;/code&gt;.
            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.
            &lt;code&gt;relativePath&lt;/code&gt; allows you to select a different location,
            for example when your structure is flat, or deeper without an intermediate parent pom.
            However, the group ID, artifact ID and version are still required,
            and must match the file in the location given or it will revert to the repository for the POM.
            This feature is only for enhancing the development in a local checkout of that project.
          </xs:documentation>
        </xs:annotation>
      </xs:element>

讀一讀英文,不行字典翻譯翻譯,然後自己做下實驗 得出如下結論:

  1. relativePath 是Maven爲了尋找父模塊pom.xml所額外增加的一個尋找路徑
  2. relativePath 默認值爲 …/pom.xml
  3. Maven 尋找父模塊pom.xml 的順序如下:
    (1)  first in the reactor of currently building projects
          這裏一個maven概念 反應堆(reactor ),
          意思就是先從工程裏面有依賴相關的模塊中找你引入的
          parent 的pom.xml,
        
    (2) then in this location on the filesystem
         然後從 你定義的  <relativePath > 路徑中找,
         當然你如果只是 /  即空值,則跳過該步驟,  
         默認值 ../pom.xml 則是從上級目錄中找啦。

    (3)  then the local repository
       這個就不說了,如果 (1) (2) 步驟沒有則從 本地倉庫找啦。

    (4) and lastly in the remote repo
     這個還用說嗎,上面都找不到了,最後只能從遠程倉庫找啦,再找不到就報錯給你看 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章