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》

  • 11
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

10km

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值