maven构建报错
编写JenkinsFile并构建的时候出了个错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project e-voucher-servert3: Failed to deploy artifacts: Could not transfer artifact com.sgai.iiot:e-voucher-servert3:jar:2.1.0-20241009.011538-1 from/to snapshots (https://maven.sgai.com.cn/repository/maven-snapshots/): authentication failed for https://maven.sgai.com.cn/repository/maven-snapshots/com/sgai/iiot/e-voucher-servert3/2.1.0-SNAPSHOT/e-voucher-servert3-2.1.0-20241009.011538-1.jar, status: 401 Unauthorized -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project e-voucher-servert3: Failed to deploy artifacts: Could not transfer artifact com.sgai.iiot:e-voucher-servert3:jar:2.1.0-20241009.011538-1 from/to snapshots (https://maven.sgai.com.cn/repository/maven-snapshots/): authentication failed for https://maven.sgai.com.cn/repository/maven-snapshots/com/sgai/iiot/e-voucher-servert3/2.1.0-SNAPSHOT/e-voucher-servert3-2.1.0-20241009.011538-1.jar, status: 401 Unauthorized
重点:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy 执行deploy失败
401 Unauthorized 没有权限
解析:
deploy 功能为,复制打包好的(最终)项目到远程仓库 / 上传到私服,共享给其它开发人员和项目。若没有确定上传的位置,deploy会自动上传到默认Maven中心库。
而中心库无法随意上传项目,需要账号密码,未设置账号密码的上传自然被认定为(没有权限)。
解决方法1:不上传(删掉deploy)
withMaven(jdk: 'jdk17', maven: 'maven') {
// 删掉代码最后的deploy
sh 'mvn -s "/var/jenkins_home/apache-maven-3.8.2/conf/settings_iip.xml" clean package -X -P dev deploy'
}
解决方法2:添加账号密码配置
解决方法3:上传到私人服务器(修改上传地址)