今天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中的配置:
releases Nexus Release Repository http://192.168.1.X:8081/nexus/content/repositories/releases/ snapshots Nexus Snapshot Repository http://192.168.1.X:8081/nexus/content/repositories/snapshots/
下面是我settings.xml的配置:
nexus-releases admin admin nexus-snapshots admin admin
比较可以看到 pom中repository和snapshotRepository两个库的id没有与settings.xml中对应起来。修改一致即可发布成功。