尝试访问 Nexus 私有存储库时,maven 收到“未授权”

2024-06-25

我在 EC2 实例上设置了一个私有 Nexus 存储库管理器,并按照互联网上流传的有关如何设置 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.

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

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

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


哦,我的时髦山羊。 问题在于,显然在 settings.xml 中,Id 字段必须与服务器字段中的字段相同。 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>

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

尝试访问 Nexus 私有存储库时,maven 收到“未授权” 的相关文章

随机推荐