Maven error: Not authorized, ReasonPhrase:Unauthorized
Solution 1
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.
Solution 2
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
Solution 3
I have recently encountered this problem. Here are the steps to resolve
- 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>
- 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>
- 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.
Solution 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.
Solution 5
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.
Mahendra Liya
Updated on July 09, 2022Comments
-
Mahendra Liya almost 2 years
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 executingmvn install clean
I get the error sayingNot 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
-
dokaspar over 11 yearswhat was the problem with the characters / letters? and how did you solve it?
-
Mahendra Liya over 11 yearsThe 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..
-
chapeljuice almost 10 yearsCouldn'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.
-
Paulo Oliveira about 9 yearsThis will work even If I use a SOCKS proxy on Maven?
-
jp093121 over 7 yearsNote: On Windows, my settings.xml file was located in [ %USER_HOME%/.m2/settings.xml ], after adding the above, I no longer got the Unauthorized
-
splintor over 6 yearsThe comment about the
clean
order saved me. After adding a dependency to the repositorymvn install
kept failing, until I realized I need to domvn clean install
. Thanks! -
Norbert about 6 yearsI 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.
-
Vineela Thonupunuri over 5 years..\Maven\apache-maven-3.5.2\conf that is the path to your settings.xml
-
Ordiel about 2 yearsThat does not seem to be quite the alternative, specially if you care about security at your workplace