日志问题现象

1
Caused by: org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException: Failed to deploy artifacts: Could not transfer artifact com.aa.bb:client:jar:1.0.0-20191231.021137-1 from/to company::default (http://test.company.local/nexus/repository/maven-snapshots): Transfer failed for http://test.company.local/nexus/repository/maven-snapshots/com/aa/bb/client/1.0.0-SNAPSHOT/client-1.0.0-20191231.021137-1.jar 401 Unauthorized

根据提示,401未授权,表面来看就是发布的权限未认证

排查步骤

settings文件是否配置了发布的用户名与密码,且用户有deploy的权限

1
2
3
4
5
6
7
<servers>
  <server>
    <id>myid</id>
    <username>myuser</username>
    <password>mypasswd</password>
  </server>
</servers>

查看deploy插件的版本

  1. 如果是2.X的版本,可以使用以下命令进行发布
1
mvn -DaltDeploymentRepository=company::default::http://test.compnay.local/nexus/repository/maven-snapshots clean package deploy
  1. 如果是3.X的版本,则需要按3.X版本进行指定发布
1
mvn deploy:deploy-file -Dfile=xxx-1.0.0-SNAPSHOT.jar -Durl=http://test.local/nexus/content/repositories/snapshots -DrepositoryId=test-snapshot

Deploy 3.0.0-M1的发布bug

如果配置的deploy的插件为3.0.0-M1,则可参考3.0.0-M1 401 bug 进行修改,具体就是指定depoly版本为2.8,根据插件作者的回复感觉就是3.0.0-M1与altDeploymentRepository参数不能一起用