[英]Which URLs does Maven resolve with a subpath in child POMs?
我在某處讀到,如果Maven項目使用繼承,則其子項目將使用子項目的artifactId
自動向URL添加子路徑。 但是現在我找不到參考。
Maven將從父POM逐字繼承哪些繼承的URL,並將為子POM添加子路徑? 例如,以下是一些我可以找到的URL:
<project><url>
<project><scm><url>
<project><distributionManagement><site><url>
也許我弄錯了,沒有一個添加子路徑,但是我在筆記中有它。 不幸的是,我似乎無法使用Internet搜索找到確切的答案。
請嘗試在回答中提供權威參考。 (當然,如果沒有相關文檔,則直接測試將是第二好的選擇。)預先感謝。
所有這些元素均在正確記錄的Maven XSD架構中定義( xs:documentation
標記)。
以下是網址的文檔:
project.url
(第102行):
項目主頁的URL。
默認值為:父值[+路徑調整] +(artifactId或project.directory屬性)
路徑調整僅在子項目的路徑與其工件標識不匹配時才適用。
project.directory
是一個屬性,您可以在properties
標記中覆蓋它。
site.url
(第544行):
網站部署位置的網址,格式為
protocol://hostname/path
。
默認值為 :父值[+路徑調整] + artifactId
scm.url
(第823行):
項目的可瀏覽SCM存儲庫的URL,例如ViewVC或Fisheye。
默認值為 :父值[+路徑調整] + artifactId
因此,所有這些元素的默認值包括路徑調整和artifactId。
還有其他幾個名為url
元素。 並非所有這些文件都經過路徑調整,例如,存儲庫的URL不是。
讓我們創建一個涵蓋以上所有選項的示例。
對於此示例,我們需要一個具有三個模塊的項目( maven-urls
):
child-project
-一個常規子模塊,不會覆蓋任何內容。 child-with-a-project-directory
-聲明project.directory
屬性的子模塊。 path-adjusted-child
child-具有意外相對路徑的子模塊。 。 目錄結構應如下所示:
maven-urls
child-project
child-with-a-project-directory
path
path-adjusted-child
父項目pom
在這里,我們將聲明三個不同的url和子項目(請注意path-adjusted-child
):
...
<url>https://example.com</url>
<scm>
<url>https://example.com/scm</url>
</scm>
<modules>
<module>child-project</module>
<module>path/path-adjusted-child</module>
<module>child-with-a-project-directory</module>
</modules>
<distributionManagement>
<site>
<url>https://example.com/distribution</url>
</site>
</distributionManagement>
...
項目目錄
對於child-with-a-project-directory
我們將設置一個project.directory
屬性
...
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.directory>project</project.directory>
</properties>
...
路徑調整項目
經過路徑調整的項目需要聲明到父模塊的相對路徑:
...
<parent>
...
<relativePath>../../pom.xml</relativePath>
</parent>
...
您可以在github上查看完整代碼: https : //github.com/defaultlocale/maven-urls 。
現在,我們可以構建整個項目並檢查值。 我們可以使用maven幫助插件,它的effective-pom
目標是找到每個子項目的有效URL。
mvn help:effective-pom
這是所有這些的輸出:
child-project
:
<url>https://example.com/child-project</url>
<scm>
<url>https://example.com/scm/child-project</url>
</scm>
<distributionManagement>
<site>
<url>https://example.com/distribution/child-project</url>
</site>
</distributionManagement>
這里沒有什么意外的。 每個URL只是一個附加了artifactId
的父URL。
child-with-a-project-directory
:
...
<url>https://example.com/project</url>
<scm>
<url>https://example.com/scm/project</url>
</scm>
<distributionManagement>
<site>
<url>https://example.com/distribution/project</url>
</site>
</distributionManagement>
...
事實證明, project.directory
覆蓋了所有三個URL的artifactId
。 這是意外的,並且不在文檔中涵蓋。
path-adjusted-child
:
<url>https://example.com/path/path-adjusted-child</url>
<scm>
<url>https://example.com/scm/path/path-adjusted-child</url>
</scm>
<distributionManagement>
<site>
<url>https://example.com/distribution/path/path-adjusted-child</url>
</site>
</distributionManagement>
...
毫不奇怪,每個URL都包含相對路徑和artifactId。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.