Resources Blog What to Do When Sonatype Nexus Returns '401'

What to Do When Sonatype Nexus Returns '401'

Sonatype helps open source projects by providing free Maven repository hosting and Maven central repository sync. There are hundreds of projects using this great service. As a result, I've received many questions from users, and a large amount of them is about '401'. It is sometimes the case that when people try to deploy artifacts into Sonatype Nexus Repository using Maven, the deployment fails and they receive a 401 error.

The general definition of '401' can be bound at the HTTP RFC. Briefly speaking, a '401' error occurs when the server asks for user authentication but the client can not provide it. In Sonatype Nexus, this means the Sonatype Nexus server asks you log in first before doing things like deploying artifacts. So when you get a 401 on deploying artifacts to Sonatype Nexus, you need to make sure you provide correct credentials.

Here is a check list you can follow:

  • Make sure your username/password is correct by logging into the Sonatype Nexus UI. If curl is installed on your machine, you can try deploying an artifact with a command like this:

curl -u juven-test:****** juvenxu/ossrh-test/1.1/ossrh-test-1.1.pom --request PUT --data @pom.xml

  • If there is no error output, ensure your user privileges are correctly configured on the server. Make sure to drop the repo you just created.
  • Make sure you have configured a server in settings.xml and that the server id is identical to the distribution repository id in pom.xml. For example, this:

    sonatype-nexus-staging Nexus Staging Repository 


<settings> ... <servers> <server> <id>sonatype-nexus-staging</id> <username>your-jira-id</username> <password>your-jira-pwd</password></server> </servers> ... </settings>

  • Make sure your settings.xml is in the correct place (normally it's _~/.m2/settings.xml). You can check this by running mvn help:effective-settings.
  • If the server is using https but the URL in your POM is http, you might get 401 as well.
  • Use the latest version of Maven, as there is a known issue regarding 401: MNG-4469
Picture of Juven Xu

Written by Juven Xu

Juven is a former Software Engineer at Sonatype. He is now a Staff Engineer & Team Leader at Alibaba Group.