maven 获得“未授权"尝试访问 nexus 私有存储库时 [英] maven getting "Not Authorized" when trying to access nexus private repository

查看:77
本文介绍了maven 获得“未授权"尝试访问 nexus 私有存储库时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 EC2 实例上设置了一个私有的 nexus 存储库管理器,并遵循了互联网上有关如何设置 Maven 项目以使用它的各种说明.我也禁用了匿名帐户.我可以通过 curl -U username:password <the_url> 连接和复制存储库它似乎工作正常.但是,当我尝试使用 maven(任何目标)时,我得到的第一件事是

 [警告] 无法将元数据 org.apache.maven.plugins:maven-compiler-plugin/maven-metadata.xml 从/到 nexus (http://MY_NEXUS_HOST:8081/nexus/content/groups/public):未授权,ReasonPhrase:未授权.

然后 mvn 命令失败,因为它无法在任何地方找到插件.所以我可以使用 rest 命令并且它按预期工作,但不能通过 maven 的事实向我表明这是配置问题.我想我很清楚发生了什么,我已经检查并重新检查了文件,但我没有发现任何问题.这是settings.xml文件

<块引用>

<服务器><id>nexus-snapshot</id><用户名>USER_NAME</用户名><password>USER_PASSWD</password></服务器><服务器><id>nexus-release</id><用户名>USER_NAME</用户名><password>USER_PASSWD</password></服务器></服务器><镜子><镜子><!--这会将其他所有内容发送到/public --><id>nexus</id><mirrorOf>*</mirrorOf><url>http://MY_NEXUS_HOST:8081/nexus/content/groups/public</url></镜像></镜子><个人资料><个人资料><id>nexus</id><!--启用内置中央存储库的快照以直接--><!--所有通过镜像对nexus的请求--><存储库><存储库><id>中央</id><url>http://central</url><发布><已启用>真</已启用></发布><快照><已启用>真</已启用></快照></repository></repositories><插件库><插件库><id>中央</id><url>http://central</url><发布><已启用>真</已启用><updatePolicy>从不</updatePolicy></发布><快照><已启用>真</已启用><updatePolicy>总是</updatePolicy></快照></pluginRepository></pluginRepositories></个人资料></个人资料><活动配置文件><!--使配置文件始终处于活动状态--><activeProfile>nexus</activeProfile></activeProfiles>

这里是 pom 文件的相关部分

 <存储库><id>nexus-release</id><name>Nexus Release Repository</name><url>http://MY_NEXUS_HOST:8081/nexus/content/repositories/releases</url></repository><快照存储库><id>nexus-snapshot</id><name>Nexus 快照存储库</name><url>http://MY_NEXUS_HOST:8081/nexus/content/repositories/snapshots</url></snapshotRepository></distributionManagement>

我想知道是否有办法查看我遇到的确切问题.例如,如果我收到 401、403 或(出于某种原因?)404.如果有人可以帮助我,我会非常感激.哦,maven 和nexus 都是上周的最新版本.*编辑是因为无论您在点击提交之前检查多少次...

解决方案

哦,我的时髦山羊.问题是显然在 settings.xml 中,Id 字段必须与服务器字段中的字段相同.即:

<服务器><id>nexus-release</id><---这必须匹配<用户名>USER_NAME</用户名><password>USER_PASSWD</password></服务器></服务器><镜子><镜子><id>nexus-release</id><---这个<mirrorOf>*</mirrorOf><url>http://MY_NEXUS_HOST:8081/nexus/content/groups/public</url></镜像></镜子>

我想我使用哪一个并不重要(在这种情况下它们都是相同的,但这不一定总是正确的).

I've set up a private nexus repo manager on an EC2 instance and followed the various instructions floating around the internet on how to set up a maven project to use it. I have also disabled the anonymous account. I am able to connect and copy repositories via curl -U username:password <the_url> and it seems to work fine. However when I try to use maven (any goals) The very first thing I get is

    [WARNING] Could not transfer metadata org.apache.maven.plugins:maven-compiler-plugin/maven-metadata.xml from/to nexus (http://MY_NEXUS_HOST:8081/nexus/content/groups/public): Not authorized , ReasonPhrase:Unauthorized.

The mvn command then fails because it can't find the plugin anywhere. So the fact that I can use the rest command and it works as expected, but not through maven indicates to me that it is a problem with the configuration. I think I understand what's going on pretty well, and I've checked and rechecked the files, but I don't see anything wrong. Here's the settings.xml file

<servers>
  <server>
      <id>nexus-snapshot</id>
      <username>USER_NAME</username>
      <password>USER_PASSWD</password>
  </server>
  <server>
      <id>nexus-release</id>
      <username>USER_NAME</username>
      <password>USER_PASSWD</password>
  </server>

</servers>
<mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://MY_NEXUS_HOST:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases>
              <enabled>true</enabled>
          </releases>
          <snapshots>
              <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases>
              <enabled>true</enabled>
              <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
              <enabled>true</enabled>
              <updatePolicy>always</updatePolicy>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

And here is the relevent portion of the pom file

    <distributionManagement>
        <repository>
            <id>nexus-release</id>
            <name>Nexus Release Repository</name>
            <url>http://MY_NEXUS_HOST:8081/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshot</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://MY_NEXUS_HOST:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

I'm wondering if there's a way to see the exact issue I'm running into. For instance, if I'm getting a 401, 403 or (for some reason?) 404. If someone can please help me I'd be ever so greatful. Oh, both maven and nexus are the latest versions as of last week. *edited because no matter how many times you check something before hitting submit...

解决方案

Oh my funky goat. The problem was that apparently in settings.xml, the Id field has to be the same as the one in the server field. ie:

<servers>
 <server>
      <id>nexus-release</id>          <---THIS MUST MATCH
      <username>USER_NAME</username>
      <password>USER_PASSWD</password>
  </server>
</servers>
<mirrors>
    <mirror>
      <id>nexus-release</id>          <---THIS
      <mirrorOf>*</mirrorOf>
      <url>http://MY_NEXUS_HOST:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>

I guess it doesn't matter which one I use (they're both the same in this case, but that's not necessarily always true).

这篇关于maven 获得“未授权"尝试访问 nexus 私有存储库时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆