在尝试访问nexus私有存储库时,maven收到"Not Authorized"

Kev*_*ner 3 nexus maven

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

    [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.
Run Code Online (Sandbox Code Playgroud)

然后mvn命令失败,因为它无法在任何地方找到插件.所以我可以使用rest命令并且它按预期工作,但不是通过maven这一事实告诉我,这是配置问题.我想我明白发生了什么,我检查并重新检查了文件,但我没有看到任何错误.这是settings.xml文件

<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>
Run Code Online (Sandbox Code Playgroud)

这是pom文件的相关部分

    <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>
Run Code Online (Sandbox Code Playgroud)

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

Kev*_*ner 10

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

<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>
Run Code Online (Sandbox Code Playgroud)

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

  • 我整天都在战斗,这个答案是金。对我来说,这里的实际问题是某些网站上的指南是错误的,并且这些 ID 不同,而它们应该相同。 (2认同)
  • 我觉得这个答案的推理可以改进。这是有效的,因为它告诉 maven 使用服务器标签内定义的凭据,用于具有相应 id 的镜像。因此,如果您想给镜像一个不同的 id,例如“maven-central”,您可以通过在 &lt;servers&gt; 标签内添加一个“新服务器”来实现,其 id 为“maven-central”,并且具有与上面相同的凭据(如果您将存储库托管在同一个 Nexus 实例上)。这还允许使用不同的凭据将存储库托管在不同的服务器上。 (2认同)