简体   繁体   English

Maven没有从settings.xml中选择存储库的用户名

[英]maven not picking username for repository from settings.xml

I have this in my ~/.m2/settings.xml: 我的〜/ .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: 这在我的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? 为什么Maven没有选择settings.xml中指定的用户名/密码,我在做错什么吗?

Also, I have tried running maven with -X and the DEBUG log says it's reading the correct file for settings: 另外,我尝试用-X运行maven,并且DEBUG日志说它正在读取正确的设置文件:

[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

If you configure a mirror in your settings.xml you have to use the id of the mirror in the server element. 如果在settings.xml中配置镜像,则必须在服务器元素中使用镜像的ID。

<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>

If the repo is protected with BasicAuth, you can give this a go: 如果存储库受BasicAuth保护,则可以执行以下操作:

Add this to your settings.xml 将此添加到您的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: 您可以通过以下方式获得value部分:

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=

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM