Reputation: 13258
I have a Sonatype Nexus server and I want to deploy a snapshot.
This is a snippet of my settings.xml file:
<servers>
<server>
<id>test-snapshots</id>
<username>myname1</username>
<password>mypasswd1</password>
</server>
<server>
<id>test-releases</id>
<username>myname2</username>
<password>mypasswd2</password>
</server>
</servers>
And this a snippet of my pom.xml file:
<distributionManagement>
<repository>
<id>test-releases</id>
<name>Releases</name>
<url>https://nxs.company.com/content/repositories/test-releases</url>
</repository>
<snapshotRepository>
<id>test-snapshots</id>
<name>Snapshots</name>
<url>https://nxs.company.com/content/repositories/test-snapshots</url>
</snapshotRepository>
</distributionManagement>
Doing a mvn deploy
(Maven 3.0.3) I get this error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy
(default-deploy) on project MyProject: Failed to deploy artifacts:
Could not transfer artifact com.company.project:MyProject:jar:1.0.0-20121003.154427-1
from/to test-snapshots (https://nxs.company.com/content/repositories/test-snapshots):
Access denied to: https://nxs.company.com/content/repositories/test-snapshots/
com.company.project/MyProject/1.0.0-SNAPSHOT/MyProject-1.0.0-20121003.154427-1.jar
-> [Help 1]
And in my Nexus logfile, I see that no credentials are received, so it will try it later with anonymous and this will of course fail. So why are no credentials passed to Nexus?
2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.apache.shiro.session.mgt.DefaultSessionManager - Unable to resolve session ID from SessionKey [org.apache.shiro.web.session.mgt.WebSessionKey@791a17dc]. Returning null to indicate a session could not be found.
2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.sonatype.nexus.security.filter.authc.NexusContentAuthenticationFilter - No authorization found (header or request parameter)
2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.sonatype.nexus.security.filter.authc.NexusContentAuthenticationFilter - No authorization found (header or request parameter)
2012-10-03 17:24:14 DEBUG [1027496148-8353] - org.sonatype.nexus.security.filter.authc.NexusContentAuthenticationFilter - Attempting to authenticate Subject as Anonymous request...
2012-10-04 17:24:14 DEBUG [1027496148-8353] - org.sonatype.security.ldap.realms.DefaultLdapContextFactory - Initializing LDAP context using URL [ldap://10.100.100.1:3268/DC=company,DC=com] and username [[email protected]] with pooling [enabled]
Upvotes: 6
Views: 17296
Reputation: 1
you need the 'settings' element as root,
put this in your settings.xml file:
<settings>
<servers>
<server>
<id>test-snapshots</id>
<username>myname1</username>
<password>mypasswd1</password>
</server>
<server>
<id>test-releases</id>
<username>myname2</username>
<password>mypasswd2</password>
</server>
</servers>
</settings>
Upvotes: 0
Reputation: 4785
our nexus server has multiple accounts. in windows user_home/.m2/settings it has:
<server>
<!-- this id should match the id of the repo server in pom.xml -->
<id>release-nexus</id>
<username>aa</username>
<password>AA</password>
</server>
<server>
<!-- this id should match the id of the repo server in pom.xml -->
<id>snapshots-nexus</id>
<username>aa</username>
<password>AA</password>
</server>
And in project:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>some.groupid</groupId>
<artifactId>some-demo</artifactId>
<version>1.0.0</version>
<distributionManagement>
<repository>
<id>release-nexus</id>
<name>Maven Repository Switchboard</name>
<url>http://nexus.foo.net/nexus/content/repositories/aa/</url>
</repository>
<snapshotRepository>
<id>snapshots-nexus</id>
<name>Maven Repository Switchboard</name>
<url>http://nexus.foo.net/nexus/content/repositories/aa_snapshot/</url>
</snapshotRepository>
</distributionManagement>
</project>
after running mvn deploy
The output is:
All <repository>
s configured in settings are different than what we used in project pom distributionManagement
. If I put what in settings in pom, it would result in a same error forbidden
. I found the correct url when I logged in nexus server with the username and password aa
and AA
, and I found there is a aa
and aa_snapshort
. So I guess authorities for PUT
operation is actually on a much more detailed level.
Upvotes: 0
Reputation: 6832
Do you really have different username/password for each repository in Nexus? This will cause a problem with the maven http wagon because the jvm caches credentials per host and even though maven presents the alternate credentials properly, the jvm won't use them. The workaround to this is to use the webdav wagon instead since this uses the apache http client instead of the jdk urlclient.
Upvotes: 1