今天deploy一个jar包到私服上时,一直报错,原因一大串:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project ussp-common-parent: Failed to deploy artifacts: Could not transfer artifact com.ussp.common:ussp-common-parent:pom:1.0.0-20190214.060901-540 from/to snapshots (http://192.168.1.45:8081/nexus/content/repositories/snapshots/): Failed to transfer file: http://192.168.1.45:8081/nexus/content/repositories/snapshots/com/ussp/common/ussp-common-parent/1.0.0-SNAPSHOT/ussp-common-parent-1.0.0-20190214.060901-540.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
[ERROR]
可以看到最后显示,返回码是401,跟授权或权限相关。可是我的settings.xml文件里面的用户权限足够,怎么还报权限不足呢?我找了一大圈,终于发现是pom.xml文件与settings.xml关于授权相关的配置没对应起来导致的,下面是我pom中的配置:
<distributionManagement>
<repository>
<id>releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.1.X:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.1.X:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
下面是我settings.xml的配置:
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
比较可以看到 pom中repository和snapshotRepository两个库的id没有与settings.xml中对应起来。修改一致即可发布成功。