mvn deploy:deploy-file with status code 401
程序员文章站
2023-12-30 13:03:34
...
第三方jar
<dependency>
<groupId>com.abc</groupId>
<artifactId>abc-openapi-sdk</artifactId>
<version>2.0</version>
</dependency>
mvn deploy 命令:
mvn deploy:deploy-file -DgroupId=com.abc -DartifactId=abc-openapi-sdk -Dversion=2.0 -Dpackaging=jar -Dfile=abc-openapi-sdk-2.0.jar -Durl=http://artifactory.xxx.com/artifactory/thirdparty-releases-local/ -DrepositoryId=repo
解释:
- –Dversion 版本信息
- -DrepositoryId 仓库标识id
- -Durl 私服上仓库的位置,打开nexus——>repositories菜单,可以看到该路径。
- -Dfile 直接写文件名即可
如果不在当前路径,-DartifactId 要声明全路径;
坑来了,作者在上传的时候一直报 with status code 401 错误,查不到原因,
最后发现是-DrepositoryId写错了,DrepositoryId要与maven setting.xml 中仓库认证的 id 保持一致,
原来是这么写的:
mvn deploy:deploy-file -DgroupId=com.abc -DartifactId=abc-openapi-sdk -Dversion=2.0 -Dpackaging=jar -Dfile=abc-openapi-sdk-2.0.jar -Durl=http://artifactory.xxx.com/artifactory/thirdparty-releases-local/ -DrepositoryId=thirdparty-releases-local
对比setting.xml
这个必须和 nexus DrepositoryId 对应的仓库标识(id)一致才行,改成:
mvn deploy:deploy-file -DgroupId=com.abc -DartifactId=abc-openapi-sdk -Dversion=2.0 -Dpackaging=jar -Dfile=abc-openapi-sdk-2.0.jar -Durl=http://artifactory.xxx.com/artifactory/thirdparty-releases-local/ -DrepositoryId=repo
执行即可
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom ---
.......
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.503 s
[INFO] Finished at: 2021-07-15T14:03:19+08:00
[INFO] ------------------------------------------------------------------------