401 Unauthorized error⚓︎
Question⚓︎
You are receiving one of the following errors trying to publish an artifact to Central Repository:
[ERROR]
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project my-project:
Failed to deploy artifacts: Could not transfer artifact
com.mydomain:myproject:jar:1.0 from/to ossrh (https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/): authentication failed
for https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/com/mydomain/myproject/1.0/myproject-1.0.jar, status:
401 Unauthorized -> [Help 1]
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.8:deploy (injected-nexus-deploy)
on project my-project: Execution injected-nexus-deploy of goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.8:deploy failed:
Nexus connection problem to URL [https://s01.oss.sonatype.org/ ]:
401 - Unauthorized -> [Help 1]
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.13:deploy (injected-nexus-deploy)
on project my-project: Remote staging failed:
Failed to deploy artifacts: Could not transfer artifact
com.mydomain:my-project:jar.asc:sources:1.0.9 from/to ossrh (https://s01.oss.sonatype.org:443/service/local/staging/deployByRepositoryId/com-mydomain-0001): status code:
401, reason phrase: Content access is protected by token (401) -> [Help 1]
How can I fix it and be able to publish to the Central Repository?
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. Attempting to publish via OSSRH (via https://oss.sonatype.org
or
https://s01.oss.sonatype.org
) will fail unless you are specifically
provisioned to publish via that service. It is important to note that using a
plugin that does not yet support the Central Publisher Portal is not sufficient
by itself to be provisioned on the legacy OSSRH service.
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 OSSRH 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
correct 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.