maven deploy 命令的使用,及报错 401 ReasonPhrase: Unauthorized 的二种解决方式
maven deploy 的使用场景:
- 1、将私有jar包上传到maven私库
- 2、将项目上传到maven私库
- 3、将第三方依赖包上传到私库
maven命令使用前的准备工作
- 1、确认在使用的机器上安装 maven,用 mvn -version 或 mvn -v 查看
\\ 查看本地安装 maven
C:\Users\Janyue>mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: D:\JavaUtils\apache-maven-3.3.9-sts\bin\..
Java version: 1.8.0_171, vendor: Oracle Corporation
Java home: D:\JavaUtils\Java\jdk1.8.0_171\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
C:\Users\Janyue>mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: D:\JavaUtils\apache-maven-3.3.9-sts\bin\..
Java version: 1.8.0_171, vendor: Oracle Corporation
Java home: D:\JavaUtils\Java\jdk1.8.0_171\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
- 2、编写deploy 上传命令
mvn deploy:deploy-file -DgroupId=com.xx.xx -DartifactId=xxx -Dversion=2.0.7 -Dpackaging=jar -Dfile=C:\Users\Janyue\Desktop\JAR包管理\升级平台\xxx-xx.jar -Durl=http://192.168.66.166:9000/nexus/content/repositories/snapshots/ -DrepositoryId=snapshots
-
- 必传参数:
file:上传文件本地所在路径,即: jar或pom文件具体地址;
repositoryId:setting.xml 对应的仓库配置,即:仓库权限配置;
url: 仓库地址
- 必传参数:
-
- 可传参数:
groupId:组件路径,存储的包的路径,一般分为多段,第一段为域,第二段为公司名。。。对应pom中的 groupId 标签;
artifactId:组件模块 对应pom中的 artifactId 标签;
version:组件版本,这个好理解 即版本号;
- 可传参数:
报错 401 ReasonPhrase: Unauthorized 的解决方法
报错日志:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.999 s
[INFO] Finished at: 2021-07-20T15:40:42+08:00
[INFO] Final Memory: 7M/164M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom: Failed to deploy artifacts: Could not transfer artifact com.xxx.xx.core:xxx-core:jar:2.0.7-20210720.074039-15 from/to public (http://192.79.172.97:9000/nexus/content/repositories/public/): Failed to transfer file: http://192.79.172.97:9000/nexus/content/repositories/public/com/xxx/xx/xx/xx-core/2.0.7/xxx-core-2.0.7-20210720.074039-15.jar. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
- 解决方法一: 在setting.xml 配置权限
注:id与命令中的repositoryId值一致
username:即 你的私库账号
password:即 你的私库密码
<server>
<id>snapshots</id>
<username>username</username>
<password>password</password>
</server>
- 解决方法二: 直接在命令 url中 带权限执行
我采用的是这种
username:即 你的私库账号
password:即 你的私库密码
mvn deploy:deploy-file -DgroupId=com.xx.xx -DartifactId=xxx -Dversion=2.0.7 -Dpackaging=jar -Dfile=C:\Users\Janyue\Desktop\JAR包管理\升级平台\xxx-xx.jar -Durl=http://username:password@192.168.66.166:9000/nexus/content/repositories/snapshots/ -DrepositoryId=snapshots
执行结果:成功了