Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 233
praddy Avatar asked Jul 06 '13 19:07

praddy


2 Answers

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>
like image 90
Mark Schäfer Avatar answered Nov 15 '22 18:11

Mark Schäfer


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=
like image 26
thr0wable Avatar answered Nov 15 '22 16:11

thr0wable