52

I checked out my code from the Nexus repository repository. I changed the password for my account and set it correctly inside my settings.xml file. While executing mvn install clean I get the error saying Not authorized, ReasonPhrase:Unauthorized when it tries to download files from that repository.

Any idea how to solve this error? I am using Windows 7 with Maven 3.04

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Mahendra Liya
  • 12,912
  • 14
  • 88
  • 114
  • can you post the whole error? – Heetola Jun 06 '12 at 10:08
  • Just got the same error and could not figure it out either. I am using a customized settings.xml which is the same for the whole team. I downgraded to 3.0.3 and could not reproduce the same "easonPhrase:Unauthorized." issue. – Ogo Pogo Jan 02 '13 at 11:39
  • See also http://stackoverflow.com/a/32119725/32453 – rogerdpack Sep 16 '16 at 21:38

7 Answers7

38

The issue may happen while fetching dependencies from a remote repository. In my case, the repository did not need any authentication and it has been resolved by removing the servers section in the settings.xml file:

<servers>
    <server>
      <id>SomeRepo</id>
      <username>SomeUN</username>
      <password>SomePW</password>
    </server>
</servers>

ps: I guess your target is mvn clean install instead of maven install clean

blacelle
  • 2,199
  • 1
  • 19
  • 28
  • This will work even If I use a SOCKS proxy on Maven? – Paulo Oliveira Mar 24 '15 at 12:33
  • Note: On Windows, my settings.xml file was located in [ %USER_HOME%/.m2/settings.xml ], after adding the above, I no longer got the Unauthorized – jp093121 Jan 18 '17 at 17:59
  • The comment about the `clean` order saved me. After adding a dependency to the repository `mvn install` kept failing, until I realized I need to do `mvn clean install`. Thanks! – splintor Sep 27 '17 at 14:15
21

I have recently encountered this problem. Here are the steps to resolve

  1. Check the servers section in the settings.xml file.Is username and password correct?

<servers>
  <server>
    <id>serverId</id>
    <username>username</username>
    <password>password</password>
  </server>
</servers>
  1. Check the repository section in the pom.xml file.The id of the server tag should be the same as the id of the repository tag.

<repositories>
 <repository>
   <id>serverId</id>  
   <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
 </repository>
</repositories>
  1. If the repository tag is not configured in the pom.xml file, look in the settings.xml file.

<profiles>
 <profile>
   <repositories>
     <repository>
      <id>serverId</id>
      <name>aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
     </repository>
   </repositories>
 </profile>
</profiles>

Note that you should ensure that the id of the server tag should be the same as the id of the repository tag.

huanghao
  • 236
  • 2
  • 4
13

The problem here was a typo error in the password used, which was not easily identified due to the characters / letters used in the password.

Mahendra Liya
  • 12,912
  • 14
  • 88
  • 114
  • what was the problem with the characters / letters? and how did you solve it? – dokaspar Feb 04 '13 at 09:26
  • The problem was that I had the password with a missing letter. This was because the password was having few letters which were repeating and so it got had to identify the missing letter initially.. – Mahendra Liya Feb 05 '13 at 06:36
  • Couldn't add an answer anymore, but my problem was I needed to add a server to my settings.xml file that I didn't have in there yet. – chapeljuice Jun 13 '14 at 16:16
  • 1
    I resolved this error by adding the correct password to my global settings.xml. Using mvn clean install -X reveals the stack trace an that also helped. – Norbert Mar 26 '18 at 16:11
4

You have an old password in the settings.xml. It is trying to connect to the repositories, but is not able to, since the password is not updated. Once you update and re-run the command, you should be good.

1

In my case the issue was that I was executing the mvn command with "sudo".

mvn test looks for credentials here: /home/aurelio/.m2/settings.xml -> configured with repo credentials

sudo mvn test looks for credentials here: /home/root/.m2/settings.xml -> no repo credentials configured.

Aurélio Antonio
  • 166
  • 1
  • 3
  • 13
0

I also faced similar issue, but for me, my password had ! in it and to fix that I updated my nexus password without ! (I changed my password basically, you can also achieve this by escaping !, I found this issue when I tried to manually perform this operation from my jenkins node, it didn't like ! in my password) and this has resolved my issue, I'm assuming ! in my password string caused this issue when Jenkins tried to connect to SonaType Nexus from my jenkins node terminal. My issue could be totally unrelated to yours but I wanted to document my experience and solution here as well.

Shek
  • 1,543
  • 6
  • 16
  • 34
-2

I commented out/removed this part of the code from the pom.xml. And it worked. So dependencies got downloaded from maven central repos.

<repositories>
    ...
</repositories>
Siddharth Kumar
  • 2,672
  • 1
  • 17
  • 24
  • That does not seem to be quite the alternative, specially if you care about security at your workplace – Ordiel Apr 29 '22 at 14:44