当前位置: 首页 > news >正文

maven:中央仓库验证方式改变:401 Content access is protected by token

前几天向maven中央仓库发布版本,执行上传命令mvn release:perform时报错了:

[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.13:deploy (injected-nexus-deploy) on project xxxxx: Failed to deploy artifacts: Could not transfer artifact xxxxx:pom:6.0.7-20240619.183701-1 from/to ossrh (https://oss.sonatype.org/content/repositories/snapshots): authentication failed for https://oss.sonatype.org/content/repositories/snapshots/xxxxxx.pom, status: 401 Content access is protected by token -> [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

我的maven中央仓库的账号注册了好多年了,一直正常使用,没有出现过问题。

最终找到mave官方说明:《401 Unauthorized error》知道了原因:
在这里插入图片描述

此错误消息表示您可能通过提供用户名密码明文验证执行到OSSRH的发布。然而这是以前允许的与OSSRH交互的方式,现在OSSRH发布的身份验证过程的更改了,要求使用用户令牌机制。我们的有关于《设置用户令牌》的文档会对您有所帮助。

如果你是maven中央仓库的老用户,而不是新注册用户,而且忽略了最近Sonatype启用了新的基于令牌的身份验证机制,则可能遇到与我同样的情况。
以前我们在$HOME/.m2/settings.xml如下以明文形式保存maven中央仓库的验证信息

    <server><id>sonatype-nexus-snapshots</id><username>${username}</username><password>${password}</password></server><server><id>sonatype-nexus-staging</id><username>${username}</username><password>${password}</password></server>

新的基于令牌的身份验证机制要求将<username><password>字段以加密令牌形式保存。

需要参照《Generate a Token on NXRM servers》登录Nexus Repository Manager后台,在Profile/User Token/Access User Token界面如下 获取你的令牌
在这里插入图片描述
将得到的令牌数据如下更新$HOME/.m2/settings.xml中的 <username><password>字段就解决问题了。
在这里插入图片描述

参考资料

《401 Unauthorized error》
《Generate a Token on NXRM servers》
《Sonatype – 401 Content access is protected by token》

http://www.lryc.cn/news/379178.html

相关文章:

  • 【面试】http
  • 获取泛型,泛型擦除,TypeReference 原理分析
  • springboot 3.x 之 集成rabbitmq实现动态发送消息给不同的队列
  • C++ 代码实现鼠标右键注册菜单,一级目录和二级目录方法
  • SQLite 3 优化批量数据存储操作---事务transaction机制
  • [程序员] 表达的能力
  • rknn转换后精度差异很大,失真算子自纠
  • 【C语言】解决C语言报错:Stack Overflow
  • 【滚动哈希 二分查找】1044. 最长重复子串
  • webid、sec_poison_id、a1、web_session参数分析与算法实现
  • Qt|QWebSocket与Web进行通讯,实时接收语音流
  • 「51媒体」电视台媒体邀约采访报道怎么做?
  • Python提取PDF文本和图片,以及提前PDF页面中指定矩形区域的文本
  • C#实现边缘锐化(图像处理)
  • ffmpeg windows系统详细教程
  • 【单片机】MSP430G2553单片机 Could not find MSP-FET430UIF on specified COM port 解决方案
  • 每日一题——力扣104. 二叉树的最大深度(举一反三+思想解读+逐步优化)四千字好文
  • wpf textbox 有焦点 导致后台更新 前台不跟着改变
  • 数字化物资管理系统的未来:RFID技术的创新应用
  • 【docker】常用指令-表格整理
  • 洛谷——P2824 排序
  • echart在线图表demo下载直接运行
  • MLX5_SET_TO_ONES宏解析
  • SQL Server入门-SSMS简单使用(2008R2版)-1
  • 高考专业抉择探索计算机专业的未来展望及适合人群
  • windows安装spark
  • 【信息学奥赛】CSP-J/S初赛03 计算机网络与编程语言分类
  • python20 函数的定及调用
  • 【Android WebView】WebView基础
  • Python酷库之旅-第三方库openpyxl(03)