praddy
praddy

Reputation: 121

maven not picking username for repository from settings.xml

I have this in my ~/.m2/settings.xml:

<servers>
    <server>
        <username>deployment</username>
        <password>xxxxxx</password>
        <id>central</id>
    </server>
    <server>
        <username>deployment</username>
        <password>xxxxxx</password>
        <id>snapshots</id>
    </server>
</servers>

And this in my POM:

<distributionManagement>
  <repository>
      <id>central</id>
      <name>libs-release-local</name>
      <url>http://repo.example.com:8081/nexus/content/repositories/libs-release-local</url>
  </repository>
  <snapshotRepository>
      <id>snapshots</id>
      <name>libs-local</name>
      <url>http://repo.example.com:8081/nexus/content/repositories/libs-local</url>
  </snapshotRepository>
</distributionManagement>

The problem I am facing is that artifact doesn't get deployed and the nexus logs show that the username being used to authenticate is "anonymous". And that's why it's failing. Why isn't maven picking the username/password specified in the settings.xml, am I doing something wrong?

Also, I have tried running maven with -X and the DEBUG log says it's reading the correct file for settings:

[DEBUG] Reading global settings from /home/praddy/apache-maven-3.0.5/conf/settings.xml
[DEBUG] Reading user settings from /home/praddy/.m2/settings.xml
[DEBUG] Using local repository at /home/praddy/.m2/repository

Upvotes: 12

Views: 21127

Answers (2)

Mark Sch&#228;fer
Mark Sch&#228;fer

Reputation: 984

If you configure a mirror in your settings.xml you have to use the id of the mirror in the server element.

<servers>
    <server>
        <id>MIRROR-ID</id>
        <username>...</username>
        <password>...</password>
    </server>
</servers>

...

<mirrors>
    <mirror>
        <id>MIRROR-ID</id>
        <name>...</name>
        <url>...</url>
        <mirrorOf>*</mirrorOf>
    </mirror>
</mirrors>

Upvotes: 12

thr0wable
thr0wable

Reputation: 502

If the repo is protected with BasicAuth, you can give this a go:

Add this to your settings.xml

<servers>
    <server>
        <!-- Link this id here to the repo ID -->
        <id>central</id>
        <configuration>
            <httpHeaders>
                <property>
                    <name>Authorization</name>
                    <value>Basic ZGVwbG95bWVudDp4eHh4eHg=</value>
                </property>
            </httpHeaders>
        </configuration>
    </server>
</servers>

You can get the value part with:

curl -v --user deployment:xxxxxx http://repo.example.com:8081/nexus/content/repositories/libs-release-local 2>&1 | grep Authorization

Which should result in output similar to:

> Authorization: Basic ZGVwbG95bWVudDp4eHh4eHg=

Upvotes: 4

Related Questions