简单记录一下最近碰到的一次maven的deploy操作发生的报错,场景一般情况在接手组件开发的时候,如果你本地的setting配置与别人的不同,则pom文件中的repository自然与别人的不同,这样你对组件进行修改之后,deploy时必然报错:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project time-compute-utils: Failed to deploy artifacts: Could not transfer artifact xxx.xxx:time-compute-utils:jar:0.0.1-20210722.034929-26 from/to snapshots1 (http://artifactory.xxx.com/libs-xxx): Transfer failed for http://artifactory.xxx.com/libs-xxx/com/xxx/xxx/time-compute-utils/0.0.1-SNAPSHOT/time-compute-utils-0.0.1-20210722.034929-26.jar 401 Unauthorized
类似这种报错哈,不是你项目或maven配置有什么错误,问题就在于一些小配置不一样导致的。
需要检查maven的setting配置:
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-xxx</name>
<url>http://artifactory.xxx.com/libs-xxx</url>
</repository>
与pom文件中的repository配置:
<distributionManagement>
<!--repository的id根据自己的maven本地setting配置进行修改,不然会报401错误的-->
<repository>
<id>snapshots1</id>
<name>libs-xxx</name>
<!-- 只能配置成这个,这个是写的,不带local的不能写.。-->
<url>http://artifactory.xxx.com/libs-xxx</url>
</repository>
<snapshotRepository>
<id>snapshots1</id>
<name>libs-xxx</name>
<url>http://artifactory.xxx.com/libs-xxx</url>
</snapshotRepository>
</distributionManagement>
这两个配置是否时一致的,比如repository的id不一致,就会出现deploy时401,修改一下id保持一致就可以解决问题。