Why am I getting a \"401 Unauthorized\" error in Maven?
Here\'s the error I\'m getting when calling mvn deploy
(full logs at the bottom):
Failed to transfer file:
http://mcpappxxxp.dev.chx.s.com:18080/artifactory/mcprepo-release-local/Shop/loyalty-telluride/01.16.03/loyalty-tell-01.16.03.jar.
Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
Solution:
In this case you need to change the version in the pom file, and try to use a new version.
Here 01.16.03 already exist so it was failing and when i have tried with the 01.16.04 version the job went successful.
We have had this issue quite recently and found out it was to do with the version of Maven we were using. We were using 3.1.0 and could not upload to nexus, we kept getting 401's, we reverted back to 3.0.3 and the issue went away.
Easiest way to confirm is to work through the maven versions and run "mvn deploy" on your project.
Further details can be found here: https://issues.apache.org/jira/browse/WAGON-421
One of the reasons for this error is when repositoryId is not specified or specified incorrectly. As mentioned already it should be the same as in section in settings.xml. Couple of hints... Run mvn with -e -X options and check the debug output. It will tell you which repositoryId it is using:
[DEBUG] (f) offline = false
[DEBUG] (f) packaging = exe
[DEBUG] (f) pomFile = c:\temp\build-test\pom.xml
[DEBUG] (f) project = MavenProject: org.apache.maven:standalone-pom:1 @
[DEBUG] (f) repositoryId = remote-repository
[DEBUG] (f) repositoryLayout = default
[DEBUG] (f) retryFailedDeploymentCount = 1
[DEBUG] (f) uniqueVersion = true
[DEBUG] (f) updateReleaseInfo = false
[DEBUG] (f) url = https://nexus.url.blah.com/...
[DEBUG] (f) version = 13.1
[DEBUG] -- end configuration --
In this case it uses the default value "remote-repository", which means that something went wrong.
Apparently I have specified -DrepositoryID (note ID in capital) instead of -DrepositoryId.
in my case, after encrypting password,I forgot to put settings-security.xml
into ~/.m2。
This is the official explanation from sonatype nexus team about 401 - Unauthorized
I recommend you to read Troubleshooting Artifact Deployment Failures for more information.
Code 401 - Unauthorized
Either no login credentials were sent with the request, or login credentials which are invalid were sent. Checking the "authorization and authentication" system feed in the Nexus UI can help narrow this down. If credentials were sent there will be an entry in the feed.
If no credentials were sent this is likely due to a mis-match between the id in your pom's distributionManagement section and your settings.xml's server section that holds the login credentials.
I had the same error. I tried and rechecked everything. I was so focused in the Stack trace that I didn't read the last lines of the build before the Reactor summary and the stack trace:
[DEBUG] Using connector AetherRepositoryConnector with priority 3.4028235E38 for http://www:8081/nexus/content/repositories/snapshots/
[INFO] Downloading: http://www:8081/nexus/content/repositories/snapshots/com/wdsuite/com.wdsuite.server.product/1.0.0-SNAPSHOT/maven-metadata.xml
[DEBUG] Could not find metadata com.group:artifact.product:version-SNAPSHOT/maven-metadata.xml in nexus (http://www:8081/nexus/content/repositories/snapshots/)
[DEBUG] Writing tracking file /home/me/.m2/repository/com/group/project/version-SNAPSHOT/resolver-status.properties
[INFO] Uploading: http://www:8081/nexus/content/repositories/snapshots/com/...-1.0.0-20141118.124526-1.zip
[INFO] Uploading: http://www:8081/nexus/content/repositories/snapshots/com/...-1.0.0-20141118.124526-1.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
This was the key : "Could not find metadata". Although it said that it was an authentication error actually it got fixed doing a "rebuild metadata" in the nexus repository.
Hope it helps.