使用 Artifactory 时修复 Maven 依赖的技术

Technique to fix Maven Dependency when using Artifactory

所以我得到了这样的错误 Could not find artifact javax.xml.xquery:xqj-api:jar:1.0 in remote-repos 这告诉我我在 Artifactory 中的设置有问题。

问题是事情被缓存了,所以即使我解决了它我也不一定知道。

我是否应该为 Maven 创建一个备用 settings.xml 来绕过所有镜像和一个非常小的 pom.xml 只引用我感兴趣的缺失依赖项和引用 repo 的存储库语句我认为我的依赖项可能隐藏在?

或者收集需要添加到存储库管理器的存储库详细信息的最佳简约方法是什么?

您可以采用以下方法:

  1. search for the required artifact in Artifactory. If you found it, make sure you are resolving artifacts from the repository containing it. The best practice here is resolving from a virtual repository 它聚合了您需要的所有存储库。
  2. 如果您没有在 Artifactory 中找到工件,请尝试使用 remote search. Remote search will look for the artifact in Bintray JCenter
  3. 如果您没有在 JCenter 中找到工件,请尝试使用诸如 http://mvnrepository.com/. If you managed to find the artifact in a repository, add it to Artifactory as a new remote repository (assuming you trust this repository and would like to use it). You can use include/exclude 模式之类的服务来确保仅从该存储库解析特定工件。
    另一个选项是下载特定工件您需要从远程 URL 并将它们部署到本地存储库中,例如 ext-lib-releases。
    同样,请确保无论您选择什么选项,您的构建都能够解析工件。
  4. 如果您没有设法在任何 public Maven 存储库中找到工件,请尝试使用 Google 搜索工件并将所需文件部署到 Artifactory,如前所述物品。仅从您信任的站点下载并确认您下载的是 legit/valid 文件。

首先感谢@drorb 的回答,它引导我找到了以下解决问题的方法。

所以在 Maven 中你可以有多个配置文件。我定义了两个配置文件 "direct" 和 "artifactory" 并将 "direct" 设置为我的 ActiveProfile。

使用直接配置文件,即实际的 repo URL,我添加了通过搜索找到的存储库,直到构建成功。

然后我进入 Artifactory 并将所有发现的存储库输入其远程存储库列表,然后编辑 "remote-repos" 虚拟存储库并将其设置为我刚刚添加的远程存储库列表。

最后我将我的 ~/.m2/settings.xml 切换到 "artifactory" 配置文件并重建了我的项目。