Maven的pom.xml文件结构之环境配置distributionManagement

时间:2022-09-17 23:30:35

Maven项目的POM中,环境配置<distributionManagement>负责管理构件的发布。


1.<distributionManagement>的基本配置

  <distributionManagement>
...
<downloadUrl>http://jcat.myserver.org/my-project</downloadUrl>
<status>deployed</status>
</distributionManagement>
说明:

  • downloadUrl,一个URL,其他Maven项目可以通过该URL下载并引用当前Maven项目的构件。注意区别本文下面的<repository>中的URL,<repository>中的URL给出了当前Maven项目的构件的发布URL。
  • status,当前Maven项目的状态,可用的状态如下所示。注意,该值是由Maven自动设置,永远不要人工设置。
    • none,未指明状态,默认值
    • converted,该Maven项目的构件已经被转换为兼容Maven 2
    • partner,该Maven项目的构件保持与另一个库的Maven版本一致
    • deployed,该Maven项目的构件是通过Maven 2或Maven 3发布的,最常用的值
    • verified,该Maven项目的构件已经被验证过

2.<distributionManagement>的<repository>配置

给出Maven部署当前项目的构件到远程库时,关于远程库的配置。示例如下:

  <distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>corp1</id>
<name>Corporate Repository</name>
<url>scp://repo/maven2</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>propSnap</id>
<name>Propellors Snapshots</name>
<url>sftp://propellers.net/maven</url>
<layout>legacy</layout>
</snapshotRepository>
...
</distributionManagement>
具体配置参数,参考前文。

3. <distributionManagement>的<site>配置

除了部署当前Maven项目的构件,还可以部署当前Maven项目的网站和文档。示例如下:

  <distributionManagement>
...
<site>
<id>mojo.website</id>
<name>Mojo Website</name>
<url>scp://beaver.codehaus.org/home/projects/mojo/public_html/</url>
</site>
...
</distributionManagement>
这里的配置参数与<repository>中的对应配置参数一致。

4. <distributionManagement>的<relocation>配置

随着一个Maven项目的发展壮大,该Maven项目的构件可能需要重新发布到新的库。<relocation>可以将当前Maven项目以新的构件的形式发布到另一个库。示例如下:

  <distributionManagement>
...
<relocation>
<groupId>org.apache</groupId>
<artifactId>my-project</artifactId>
<version>1.0</version>
<message>We have moved the Project under Apache</message>
</relocation>
...
</distributionManagement>