[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.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工具.