Deploying artifacts on nexus from maven gives the error "Return code: 401"?

I get error 401 when deploying to a nexus. I do not make any changes to the established connection. Nexus runs on localhost:8080/nexus , and I can log in using the default user / password. When I run mvn deploy , I get this error.

Here is my POM.

  <groupId>testproject</groupId> <artifactId>testproject</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>testproject</name> <url>http://maven.apache.org</url> <distributionManagement> <repository> <id>releases</id> <url>http://localhost:8080/nexus/content/repositories/releases</url> </repository> <snapshotRepository> <id>snapshots</id> <url>http://localhost:8080/nexus/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement> <dependencies> ......... </dependencies> 

and ~ / .m2 / settings.xml

 <servers> <server> <id>snapshots</id> <username>deployment</username> <password>deployment123</password> </server> <server> <id>releases</id> <username>deployment</username> <password>deployment123</password> </server> </servers> 

An exception:

 Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default- deploy) on project testproject: Failed to deploy artifacts: Could not transfer artifact testproject:testproject:jar:1.0-20131213.150615-1 from/to snapshots (http://localhost:8080/nexus/content/repositories/snapshots): Failed to transfer file: http://localhost:8080/nexus/content/repositories/snapshots/testproject/testproject/1.0-SNAPSHOT/testproject-1.0-20131213.150615-1.jar. Return code is: 401 -> [Help 1] 

Please help me.

+7
source share
4 answers

It works now. You need to edit ${MVN_HOME}/conf/settings.xml instead of / /home/{user}/.m2/settings.xml

+18
source

HTTP 401 is the status code for "unauthorized", which means that your deployment user is not allowed to upload artifacts to this particular repository in Nexus. Log in to Nexus and give the deployment user role (s) necessary to modify this instant repo.

+3
source

I missed <servers> in my .m2/settings.xml in Gitlab-ci + MAVEN + Jfrog Artifactory:

My gitlab-ci.yxml

 Artifactory_deploy: stage: install only: - desarrollo script: - echo "Deploying to Artifactory" - cd $CLONE_DIR - mvn -X deploy 

My .m2 / settings.xml

 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> <servers> <server> <username>${ARTIFACTORY_USER}</username> <password>${ARTIFACTORY_PASSWORD}</password> <id>central</id> </server> <server> <username>${ARTIFACTORY_USER}</username> <password>${ARTIFACTORY_PASSWORD}</password> <id>snapshots</id> </server> </servers> <profiles> <profile> <id>develop</id> <properties> <artifactory.ip>${ARTIFACTORY_IP}</artifactory.ip> <artifactory.port>${ARTIFACTORY_PORT}</artifactory.port> </properties> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>libs-release</name> <username>admin</username> <password>THISWASMYENCRYPTEDPASSWORD</password> <url>http://${ARTIFACTORY_IP}:${ARTIFACTORY_PORT}/artifactory/libs-release</url> </repository> <repository> <snapshots /> <id>snapshots</id> <name>libs-snapshot</name> <username>admin</username> <password>THISWASMYENCRYPTEDPASSWORD</password> <url>http://${ARTIFACTORY_IP}:${ARTIFACTORY_PORT}/artifactory/libs-snapshot</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>libs-release</name> <username>admin</username> <password>password</password> <url>http://${ARTIFACTORY_IP}:${ARTIFACTORY_PORT}/artifactory/libs-release</url> </pluginRepository> <pluginRepository> <snapshots /> <id>snapshots</id> <name>libs-snapshot</name> <username>admin</username> <password>password</password> <url>http://${ARTIFACTORY_IP}:${ARTIFACTORY_PORT}/artifactory/libs-snapshot</url> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>develop</activeProfile> </activeProfiles> </settings> <servers> <server> <id>snapshots</id> <username>deployment</username> <password>deployment123</password> </server> <server> <id>releases</id> <username>deployment</username> <password>deployment123</password> </server> </servers> 
0
source

The user you use to deploy snapshots needs a role with these privileges:

  • th store-View-Maven2-Maven-snapshot-read
  • py-vault view-Maven2-Maven-snapshot, edit
  • th store-View-Maven2-Maven-snapshot, add
0
source

All Articles