Artifactory:如果允许匿名访问,Maven 找不到文件

Artifactory: file not found by Maven if anonymous access is allowed

我有一个 Maven 工件存储在 Artifactory 的受保护存储库中。我在 settings.xml 中设置了我的用户凭据。同时,我以允许匿名访问某些 public 存储库的方式配置了 Artifactory。

当我现在尝试使用 Maven 下载工件时,我收到以下错误消息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get (default-cli) 
  on project artifactory: Couldn't download artifact: Could not find artifact 
  XXX:common:jar:2.2.1-RELEASE in artifactory-XXX (http://XXX/artifactory/XXX)

当我在 Artifactory 中禁用匿名访问时,一切正常。

所以 Maven 在 Artifactory 服务器的 public 存储库中找不到它后,似乎没有尝试使用提供的用户凭据搜索工件。

我是否遗漏了一些 Artifactory 配置,或者无法在同一台服务器上同时拥有 public 和受保护的存储库?

您能否在 Artifactory UI --> 管理 --> 安全配置 --> 检查复选框 "Hide Existence of Unauthorized Resources" 是否被选中?

如果是这样就可以说明问题了。选中此项后,Artifactory 将不会为未经授权的用户显示工件,并将 return 404。如果这确实是问题,您可以设置 maven to use a preemptive authentication 以便从第一个请求进行身份验证。这是在 .m2/settings.xml:

中配置抢先身份验证的代码片段
<server>
  <id>artifactory</id>
  <configuration>
    <httpConfiguration>
      <all>
        <usePreemptive>true</usePreemptive>
      </all>
    </httpConfiguration>
  </configuration>
  <username>...</username>
  <password>...</password>
</server>

如果这不是问题所在,您在收到此失败消息后在 Artifactory 的 artifactory.logrequest.log 中看到了什么?