Maven最佳实践-distributionManagement
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Maven最佳实践-distributionManagement
分发构件⾄远程仓库
mvn install 会将项⽬⽣成的构件安装到本地Maven仓库,mvn deploy ⽤来将项⽬⽣成的构件分发到远程Maven仓库。
本地Maven仓库的构件只能供当前⽤户使⽤,在分发到远程Maven仓库之后,所有能访问该仓库的⽤户都能使⽤你的构件。
我们需要配置POM的distributionManagement来指定Maven分发构件的位置,如下:
Maven项⽬的POM中,环境配置<distributionManagement>负责管理构件的发布。
1.<distributionManagement>的基本配置
[html]
1. <distributionManagement>
2. ...
3. <downloadUrl>/my-project</downloadUrl>
4. <status>deployed</status>
5. </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部署当前项⽬的构件到远程库时,关于远程库的配置。
⽰例如下:
[html]
1. <distributionManagement>
2. <repository>
3. <uniqueVersion>false</uniqueVersion>
4. <id>corp1</id>
5. <name>Corporate Repository</name>
6. <url>scp://repo/maven2</url>
7. <layout>default</layout>
8. </repository>
9. <snapshotRepository>
10. <uniqueVersion>true</uniqueVersion>
11. <id>propSnap</id>
12. <name>Propellors Snapshots</name>
13. <url>sftp:///maven</url>
14. <layout>legacy</layout>
15. </snapshotRepository>
16. ...
17. </distributionManagement>
具体配置参数,参考前⽂。
3. <distributionManagement>的<site>配置
除了部署当前Maven项⽬的构件,还可以部署当前Maven项⽬的⽹站和⽂档。
⽰例如下:
[html]
1. <distributionManagement>
2. ...
3. <site>
4. <id>mojo.website</id>
5. <name>Mojo Website</name>
6. <url>scp:///home/projects/mojo/public_html/</url>
7. </site>
8. ...
9. </distributionManagement>
这⾥的配置参数与<repository>中的对应配置参数⼀致。
4. <distributionManagement>的<relocation>配置
随着⼀个Maven项⽬的发展壮⼤,该Maven项⽬的构件可能需要重新发布到新的库。
<relocation>可以将当前Maven项⽬以新的构件的形式发布到另⼀个库。
⽰例如下:
[html]
1. <distributionManagement>
2. ...
3. <relocation>
4. <groupId>org.apache</groupId>
5. <artifactId>my-project</artifactId>
6. <version>1.0</version>
7. <message>We have moved the Project under Apache</message>
8. </relocation>
9. ...
10. </distributionManagement>。