Nexus / Artifactory可以存储互联网Maven工件的副本吗?

时间:2022-11-08 23:57:47

I would like to have Nexus (or Artifactory, we're not decided yet) store a copy of an artifact when it is downloaded from a public repository on the internet (like Maven Central).

我想让Nexus(或Artifactory,我们尚未决定)在从互联网上的公共存储库(如Maven Central)下载工件时存储工件的副本。

Basically, if you don't have the jar in your local repo and the repo manager doesn't have it either, I want to ask the repo manager for the jar, have it send it to me, and store it both in the repo manager and in my local repo. Then, when another person asks the repo manager for the same jar, it sends it to them from the repo manager and they save it in their local repo, without needing to hit Maven central.

基本上,如果你的本地仓库中没有jar并且repo manager也没有它,我想向repo manager询问jar,让它发送给我,并将它们存储在repo中经理和我当地的回购。然后,当另一个人向回购经理询问同一个罐子时,它会从回购经理发送给他们,然后将它们保存在他们的本地仓库中,而不需要点击Maven central。

This sounds like how it should work out of the box, but I don't see it. I can see the artifacts on Maven central through the repo manager, but when I use Netbeans to add a dependency to my project, it downloads it straight from Maven central (apparently). Nothing gets cached in the repo manager (as far as I can see).

这听起来像它应该如何开箱即用,但我没有看到它。我可以通过repo管理器在Maven中心看到工件,但是当我使用Netbeans为我的项目添加依赖项时,它会直接从Maven中心下载(显然)。在repo管理器中没有任何东西被缓存(据我所知)。

3 个解决方案

#1


5  

Nexus has the concept of proxy repository which does almost exactly what you describe. See the Proxying Public Repositories section of the book for details.

Nexus具有代理存储库的概念,几乎完全符合您的描述。有关详细信息,请参阅本书的“代理公共存储库”部分。

Artifactory has a similar feature called Virtual repositories.

Artifactory具有类似的功能,称为虚拟存储库。

Proxying and caching a remote public repository can speed up your builds by reducing redundant downloads over the public internet. If a developer in your organization needs to download version 2.5 of the Spring Framework and you are using Nexus, the dependencies (and the dependency's dependencies) only need to be downloaded from the remote repository once. With a high-speed connection to the Internet this might seem like a minor concern, but if you are constantly asking your developers to download hundreds of megabytes of third-party dependencies, the real cost savings are going to be the time it takes Maven to check for new versions of dependencies and to download dependencies over the public internet.

代理和缓存远程公共存储库可以通过减少公共Internet上的冗余下载来加速构建。如果组织中的开发人员需要下载Spring Framework 2.5版并且您正在使用Nexus,则只需要从远程存储库下载一次依赖项(以及依赖项的依赖项)。通过与Internet的高速连接,这似乎是一个小问题,但如果您不断要求开发人员下载数百兆的第三方依赖项,那么实际节省的成本将是Maven需要的时间。检查新版本的依赖项并通过公共Internet下载依赖项。

You can stop your Maven install from ever trying to connect to Central by setting up your repository manager as a mirror of central, requests to central will then be directed to your repository manager. For example add the following to the <mirrors> section of Maven's settings.xml to redirect requests to central to your repository manager:

您可以通过将存储库管理器设置为*镜像来阻止Maven安装尝试连接到Central,然后将对Central的请求定向到您的存储库管理器。例如,将以下内容添加到Maven的settings.xml的 部分,以将请求重定向到您的存储库管理器的*:

<mirror>
  <id>central-proxy</id>
  <mirrorOf>central</mirrorOf>
  <url>http://myrepo/nexus/content/groups/public</url>
</mirror>

I tend to set up a repository group containing several remote repositories. The group acts as a single repository as far as my Maven install is concerned, but collates artifacts from several remote repositories.

我倾向于设置一个包含多个远程存储库的存储库组。就我的Maven安装而言,该组充当单个存储库,但整理来自多个远程存储库的工件。

#2


2  

Proxying and caching artifacts from other public repositories is (or should be) indeed built-in in any decent enterprise repository manager. In a corporate environment, development teams should be able to develop and build their software even when a public repository is down. This is a very basic use case and one of the reasons to use a corporate repository (not being dependent on public resources that you don't control).

来自其他公共存储库的代理和缓存工件确实(或应该)内置于任何体面的企业存储库管理器中。在企业环境中,即使公共存储库出现故障,开发团队也应该能够开发和构建他们的软件。这是一个非常基本的用例,也是使用公司存储库的原因之一(不依赖于您无法控制的公共资源)。

Once the repository manager is installed and configured, you'll need to configure maven to check the repository instead of the public repositories. To do this, edit your mirror settings (as pointed out by Rich) in your ~/.m2/settings.xml. Refer to the section 3.2. Configuring Maven to Use a Single Nexus Group of the Nexus Book for more details (the configuration applies to any repository manager).

安装并配置存储库管理器后,您需要配置maven以检查存储库而不是公共存储库。要执行此操作,请在〜/ .m2 / settings.xml中编辑镜像设置(如Rich所指出的)。请参阅第3.2节。配置Maven以使用Nexus Book的单个Nexus组获取更多详细信息(该配置适用于任何存储库管理器)。

In a corporate environment, I prefer to force Maven to use a single repository by having it mirror all repository requests. To achieve this, set mirrorOf to *.

在企业环境中,我更愿意通过让Maven镜像所有存储库请求来强制使用单个存储库。要实现此目的,请将mirrorOf设置为*。

<settings>
  ...
  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>Maven Repository Manager running on repo.mycompany.com</name>
      <url>http://repo.mycompany.com/proxy</url>
    </mirror>
  </mirrors>
  ...
</settings>

#3


1  

In Artifactory, you can use the "Home->Maven Settings" page to download a maven settings that will enforce maven to use only Artifactory virtual repositories you choose. This combined with repository reference cleanup in Virtual repositories will make sure you will never query maven central.

在Artifactory中,您可以使用“Home-> Maven设置”页面下载maven设置,该设置将强制maven仅使用您选择的Artifactory虚拟存储库。这与虚拟存储库中的存储库引用清理相结合,将确保您永远不会查询maven中心。

Your issue with NetBeans may be solved by enforcing the repo declaration in your Maven installation. The last time I used NetBeans Maven support, I also specified a project level settings.xml file to cover every cases.

您可以通过在Maven安装中强制执行repo声明来解决NetBeans的问题。我最后一次使用NetBeans Maven支持时,还指定了一个项目级settings.xml文件来覆盖每个案例。

Side Note: Using the mirrorOf feature is very rude and may lead to strange behavior.

侧注:使用mirrorOf功能非常粗鲁,可能会导致奇怪的行为。

#1


5  

Nexus has the concept of proxy repository which does almost exactly what you describe. See the Proxying Public Repositories section of the book for details.

Nexus具有代理存储库的概念,几乎完全符合您的描述。有关详细信息,请参阅本书的“代理公共存储库”部分。

Artifactory has a similar feature called Virtual repositories.

Artifactory具有类似的功能,称为虚拟存储库。

Proxying and caching a remote public repository can speed up your builds by reducing redundant downloads over the public internet. If a developer in your organization needs to download version 2.5 of the Spring Framework and you are using Nexus, the dependencies (and the dependency's dependencies) only need to be downloaded from the remote repository once. With a high-speed connection to the Internet this might seem like a minor concern, but if you are constantly asking your developers to download hundreds of megabytes of third-party dependencies, the real cost savings are going to be the time it takes Maven to check for new versions of dependencies and to download dependencies over the public internet.

代理和缓存远程公共存储库可以通过减少公共Internet上的冗余下载来加速构建。如果组织中的开发人员需要下载Spring Framework 2.5版并且您正在使用Nexus,则只需要从远程存储库下载一次依赖项(以及依赖项的依赖项)。通过与Internet的高速连接,这似乎是一个小问题,但如果您不断要求开发人员下载数百兆的第三方依赖项,那么实际节省的成本将是Maven需要的时间。检查新版本的依赖项并通过公共Internet下载依赖项。

You can stop your Maven install from ever trying to connect to Central by setting up your repository manager as a mirror of central, requests to central will then be directed to your repository manager. For example add the following to the <mirrors> section of Maven's settings.xml to redirect requests to central to your repository manager:

您可以通过将存储库管理器设置为*镜像来阻止Maven安装尝试连接到Central,然后将对Central的请求定向到您的存储库管理器。例如,将以下内容添加到Maven的settings.xml的 部分,以将请求重定向到您的存储库管理器的*:

<mirror>
  <id>central-proxy</id>
  <mirrorOf>central</mirrorOf>
  <url>http://myrepo/nexus/content/groups/public</url>
</mirror>

I tend to set up a repository group containing several remote repositories. The group acts as a single repository as far as my Maven install is concerned, but collates artifacts from several remote repositories.

我倾向于设置一个包含多个远程存储库的存储库组。就我的Maven安装而言,该组充当单个存储库,但整理来自多个远程存储库的工件。

#2


2  

Proxying and caching artifacts from other public repositories is (or should be) indeed built-in in any decent enterprise repository manager. In a corporate environment, development teams should be able to develop and build their software even when a public repository is down. This is a very basic use case and one of the reasons to use a corporate repository (not being dependent on public resources that you don't control).

来自其他公共存储库的代理和缓存工件确实(或应该)内置于任何体面的企业存储库管理器中。在企业环境中,即使公共存储库出现故障,开发团队也应该能够开发和构建他们的软件。这是一个非常基本的用例,也是使用公司存储库的原因之一(不依赖于您无法控制的公共资源)。

Once the repository manager is installed and configured, you'll need to configure maven to check the repository instead of the public repositories. To do this, edit your mirror settings (as pointed out by Rich) in your ~/.m2/settings.xml. Refer to the section 3.2. Configuring Maven to Use a Single Nexus Group of the Nexus Book for more details (the configuration applies to any repository manager).

安装并配置存储库管理器后,您需要配置maven以检查存储库而不是公共存储库。要执行此操作,请在〜/ .m2 / settings.xml中编辑镜像设置(如Rich所指出的)。请参阅第3.2节。配置Maven以使用Nexus Book的单个Nexus组获取更多详细信息(该配置适用于任何存储库管理器)。

In a corporate environment, I prefer to force Maven to use a single repository by having it mirror all repository requests. To achieve this, set mirrorOf to *.

在企业环境中,我更愿意通过让Maven镜像所有存储库请求来强制使用单个存储库。要实现此目的,请将mirrorOf设置为*。

<settings>
  ...
  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>Maven Repository Manager running on repo.mycompany.com</name>
      <url>http://repo.mycompany.com/proxy</url>
    </mirror>
  </mirrors>
  ...
</settings>

#3


1  

In Artifactory, you can use the "Home->Maven Settings" page to download a maven settings that will enforce maven to use only Artifactory virtual repositories you choose. This combined with repository reference cleanup in Virtual repositories will make sure you will never query maven central.

在Artifactory中,您可以使用“Home-> Maven设置”页面下载maven设置,该设置将强制maven仅使用您选择的Artifactory虚拟存储库。这与虚拟存储库中的存储库引用清理相结合,将确保您永远不会查询maven中心。

Your issue with NetBeans may be solved by enforcing the repo declaration in your Maven installation. The last time I used NetBeans Maven support, I also specified a project level settings.xml file to cover every cases.

您可以通过在Maven安装中强制执行repo声明来解决NetBeans的问题。我最后一次使用NetBeans Maven支持时,还指定了一个项目级settings.xml文件来覆盖每个案例。

Side Note: Using the mirrorOf feature is very rude and may lead to strange behavior.

侧注:使用mirrorOf功能非常粗鲁,可能会导致奇怪的行为。