Maven发布代码,401错误问题解决,with status code 401

58 篇文章 0 订阅
16 篇文章 0 订阅

[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1
.6.7:deploy (injected-nexus-deploy) on project yy: Failed to deploy artifacts
: Could not transfer artifact org.xx:yy:jar:sources:2.4.0-20240622.16414
2-1 from/to ossrh (https://oss.sonatype.org/content/repositories/snapshots): Fai
led to transfer file https://oss.sonatype.org/content/repositories/snapshots/org
/xxx/yyy/2.4.0-SNAPSHOT/yy-2.4.0-20240622.164142-1-sources.jar with status code 401 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[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 rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception

maven上传到中央仓库, SNAPSHOT库报以上401错误,是什么原因?

原因有几种,

1. 使用了新的方式, 旧的方式不支持了.  

https://central.sonatype.org

新的方式(已使用旧方式的域名是不能用新方式的,不支持同时用)

https://central.sonatype.com/account

登录后:

2. 地址改了,由原来oss.sonatype.org改为:s01.oss.sonatype.org.

在是在2024年6月前还正常上传, 在6月突然不行了. 而原来也不使用这个新域名的话,这个是可以排除的.

3. 若是在2024年6月前还正常上传, 在6月突然不行了.  很大原因是原来使用用户名,密码,现要在使用token了. 

将maven的settings.xml,

 <server>
      <id>ossrh</id>
      <username>username</username>
      <password>password</password>
   </server>

改为:

 <server>
      <id>ossrh</id>
      <username>token-username</username>
      <password>token-password</password>
   </server>

问题是如何创建token的name及password.

登录旧的url,并在以下地址,创建token即可.

https://oss.sonatype.org/#profile;User%20Token

注意, 使用旧的方式发布过代码的, 同样的maven坐标是不支持在新的方式重新登记namespace命名空间的. 即不能在旧的和新的都发布有同样坐标的代码.所以之前发布过的,报401,就不要折腾新方式了.


https://central.sonatype.org/faq/401-error/#question

Answer⚓︎
There are multiple reasons why you are getting this error, please evaluate each of them below:

Signed up on central.sonatype.com

If you signed up to publish via central.sonatype.com, you should follow the publishing documentation for Maven, Gradle, uploading manually, or via the Publisher API. As the system is very new, there are a lot of third-party, community resources that direct people to publish via plugins that are compatible with OSSRH, which is a source of potential confusion.

401 Content access is protected by token

This error message indicates that you are likely publishing to OSSRH via your username and password. While this was a previously allowed way of interacting with OSSRH, changes to the authentication process have resulted in publishing requiring the use of a user token. We have documentation on setting up a user token that will help.

Wrong credentials (username/password) in your setup

This is the most common reason for this error, a typo in your password or maybe the usage of a user without the publishing permissions could be the reason of the error. Confirm the right credentials and that the user has the required permissions. A common test is to login to the web console of the OSSRH Sonatype Nexus Repository Manager server (https://s01.oss.sonatype.org or https://oss.sonatype.org depending on where your project was registered) and use the credentials, you should not have problems logging into it if the credentials are right.

Password may contain unsupported characters (localized characters, symbols, non-ASCII)

Update your password as described in the documentation and set a new one without special characters. You could also generate an authentication token and use it to publish to the Central Repository.

You are trying to publish using the wrong OSSRH server

Since 2021, new projects are being hosted in the new server https://s01.oss.sonatype.org. If you are using an old documentation that may still be referring to the old OSSRH server oss.sonatype.org. Please update your pom.xml and configuration files with the new server s01.oss.sonatype.org.

If you still are getting a 401 HTTP error and none of the above solutions work for you, please contact Central Support.

ORM Bee, 一个简单易用,功能又功能的Java ORM工具.

https://github.com/automvc/bee

  • 23
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Maven deploy status: 401 Unauthorized表示Maven部署失败,返回了未授权的状态码401。这通常是由于访问凭据不正确或缺失而引起的。 造成此问题的可能原因有以下几点: 1. 访问凭据错误:部署到Maven仓库需要提供正确的用户名和密码。如果凭据错误或丢失,就会返回401未授权的错误。确保提供的用户名和密码是正确的,并且具有访问仓库所需的权限。 2. 凭据配置错误:在Maven的settings.xml配置文件中,凭据可能没有正确配置。检查该文件,确保仓库的凭据正确配置,并且与部署命令中使用的凭据相匹配。 3. 仓库访问权限:某些Maven仓库可能需要使用特定的权限或角色才能进行部署操作。检查你是否被授予了正确的权限,并且具有执行部署操作的权限。 4. 仓库地址错误:请确保在Maven的pom.xml文件或命令行参数中使用了正确的仓库地址。如果仓库地址错误Maven将无法连接到正确的仓库进行部署操作。 解决Maven deploy status: 401 Unauthorized问题的方法包括: 1. 检查凭据:确保提供的凭据是正确的,包括正确的用户名和密码,并且具有相应仓库的访问权限。 2. 检查配置:检查Maven的settings.xml配置文件中的仓库凭据配置是否正确,确保凭据与部署命令中使用的凭据相匹配。 3. 申请权限:如果你没有正确的权限来访问仓库进行部署操作,请联系管理员或仓库所有者申请相应的权限。 4. 检查仓库地址:确保在部署命令或pom.xml文件中使用了正确的仓库地址,以便Maven能够连接到正确的仓库进行部署。 总之,Maven deploy status: 401 Unauthorized表示Maven部署过程中出现了未授权的错误401,你需要检查和确保提供的凭据、配置、权限和仓库地址都是正确的。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值