Maven之Deploy使用

背景

目前公司里的项目定制一般不需要用到Deploy(上传jar包到af仓库上),定制只是下载依赖然后使用。最近开发组件过程中,由于需要组件提供对外api给其它组件使用,在使用的过程中也不是特别顺利,所以记录一下Deploy的使用。

Deploy

Deploy是Maven生命周期的最后一个环节,作用是上传最终的成果物到远程仓库中,共享给其它开发人员和工程。使用方法如下:

Step 1:需要在settings.xml配置af仓库的用户名和密码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     | 
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are 
     |       used together.
     |
	-->
	
	<server>
		<id>xxx-release</id>
		<username>xxx</username>
		<password>xxx</password>
	</server>

  </servers>

Step 2:要Deploy的module的pom文件中添加要上传的af仓库,id要和上面settings.xml中的id对应

1
2
3
4
5
6
7
8
    <distributionManagement>
        <repository>
            <id>xxx-release</id>
            <name>xxx-release</name>
            <url>xxx</url>
        </repository>
        
    </distributionManagement>

Srtep 3: 执行deploy命令,右侧maven工具栏中找到相应的module执行即可。deploy完在af仓库的地址中可以查询:xxx

Deploy注意事项

  • 如果只需要deploy xx-external-api module的话,需要注意在其父module api也需要deploy,直接在api的pom文件中deploy即可,会递归执行xx-external-api module。
  • 报错403,403有时候并不是用户名或密码错误,分为download和deploy两种情况
    • download: 有可能是ah仓库中没有该依赖,根据报错的url查看是否有该依赖
    • deploy: 有可能是 release 包重复上传
    • 接上一条,release包无法重复上传,无法重复上传,无法重复上传,重复上传后目前无法删除,只能修改版本号重新上传
  • 报错409,一般是针对pom文件报错,根据官方文档所说,409是在进行pom文件的一致性检查时出现问题,这时候需要检查你的pom文件的artifactid和groupid和version是否正确
    • 我遇到的错误是snapshot的版本号写错,需要注意*snapshot的版本号只能写成1.0.0-SNAPSHOT,注意是-SNAPSHOT
  • 针对上述403和409问题,在项目开发中,一定要严格使用SNAPSHOT版本号,版本发布的时候改为RELEASE作为稳定版本。