我怎样才能让Maven停止尝试从maven-central-repo检查来自某个组的工件的更新?

时间:2021-08-18 11:59:35

I'm working on a fairly big Maven project. We have probably around 70 or so individual artifacts, which are roughly split into two libraries of shared code and maybe ten applications which use them. All of these items live in the namespace com.mycompany.*.

我正在研究一个相当大的Maven项目。我们可能有大约70个左右的单个工件,它们大致分为两个共享代码库,也许有十个使用它们的应用程序。所有这些项都存在于命名空间com.mycompany。*中。

Most of the time we're running against snapshot builds. So to do a full build of an application, I might first build the library projects so that they are installed to my local repository (as, say, mycompany-libname-2.4-SNAPSHOT.jar).

大部分时间我们都在针对快照构建运行。因此,为了完整构建应用程序,我可能首先构建库项目,以便将它们安装到我的本地存储库(例如,mycompany-libname-2.4-SNAPSHOT.jar)。

The problem is that when I then go build the applications. For some reason, Maven wants to check the main two public repositories (maven-net-repo and java-net-repo) for updates for all of the mycompany-*-SNAPSHOT.jar artifacts. Of course, they aren't found there, and everything eventually resolves back to the versions I just built to my local repository, but I'd like Maven to stop doing this because (a) it makes me feel like a bad net.citizen for constantly checking these repositories for things that will never be there, and (b) it adds some unnecessary and annoying network latency into my build process.

问题是,当我然后构建应用程序。出于某种原因,Maven想要检查主要的两个公共存储库(maven-net-repo和java-net-repo)以获取所有mycompany - * - SNAPSHOT.jar工件的更新。当然,它们在那里找不到,一切最终都会回归到我刚建立到本地存储库的版本,但是我希望Maven停止这样做,因为(a)它让我感觉像是一个糟糕的net.citizen用于不断检查这些存储库以寻找永远不存在的东西,并且(b)它在我的构建过程中添加了一些不必要且烦人的网络延迟。

I've taken to running maven in offline mode most of the time to work around this, but that's not ideal since occasionally a dependency on a public library will be updated. So what I'm looking for is a solution which will cause Maven not to check for updates from given repositories for artifacts which meet certain criteria - in this case, I'd be happy if Maven would ignore either SNAPSHOT versions or artifacts which were in the com.mycompany namespace.

我大部分时间都在离线模式下运行maven来解决这个问题,但这并不理想,因为偶尔会更新对公共库的依赖。所以我正在寻找的是一个解决方案,它将导致Maven不检查来自给定存储库的更新是否符合某些标准的工件 - 在这种情况下,如果Maven忽略SNAPSHOT版本或其中的工件,我会很高兴com.mycompany名称空间。

6 个解决方案

#1


27  

The updatePolicy tag didn't work for me. However Rich Seller mentioned that snapshots should be disabled anyways so I looked further and noticed that the extra repository that I added to my settings.xml was causing the problem actually. Adding the snapshots section to this repository in my settings.xml did the trick!

updatePolicy标记对我不起作用。但Rich Seller提到应该禁用快照,所以我进一步观察并注意到我添加到settings.xml的额外存储库实际上导致了问题。在我的settings.xml中将快照部分添加到此存储库就可以了!

<repository>
    <id>jboss</id>
    <name>JBoss Repository</name>
    <url>http://repository.jboss.com/maven2</url>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
</repository>

#2


139  

Also, you can use -o or --offline in the mvn command line which will put maven in "offline mode" so it won't check for updates. You'll get some warning about not being able to get dependencies not already in your local repo, but no big deal.

此外,您可以在mvn命令行中使用-o或--offline,这将使maven处于“脱机模式”,因此它不会检查更新。您将收到一些警告,说明无法获取本地仓库中尚未存在的依赖项,但没什么大不了的。

#3


76  

Something that is now available in maven as well is

现在在maven中也可以使用的东西是

mvn goal --no-snapshot-updates

or in short

或简而言之

mvn goal -nsu

#4


29  

Update: I should have probably started with this as your projects are SNAPSHOTs. It is part of the SNAPSHOT semantics that Maven will check for updates on each build. Being a SNAPSHOT means that it is volatile and subject to change so updates should be checked for. However it's worth pointing out that the Maven super POM configures central to have snapshots disabled, so Maven shouldn't ever check for updates for SNAPSHOTs on central unless you've overridden that in your own pom/settings.

更新:我应该从这开始,因为你的项目是SNAPSHOTs。它是SNAPSHOT语义的一部分,Maven将检查每个构建的更新。作为SNAPSHOT意味着它是易变的并且可能会发生变化,因此应该检查更新。然而,值得指出的是,Maven超级POM配置中心以禁用快照,因此Maven不应该检查*SNAPSHOT的更新,除非您在自己的pom /设置中覆盖了它。


You can configure Maven to use a mirror for the central repository, this will redirect all requests that would normally go to central to your internal repository.

您可以将Maven配置为使用镜像作为*存储库,这将重定向通常发送到内部存储库的所有请求。

In your settings.xml you would add something like this to set your internal repository as as mirror for central:

在您的settings.xml中,您将添加类似这样的内容以将内部存储库设置为*镜像:

<mirrors>
  <mirror>
    <id>ibiblio.org</id>
    <name>ibiblio Mirror of http://repo1.maven.org/maven2/</name>
    <url>http://path/to/my/repository</url>
    <mirrorOf>central</mirrorOf>
  </mirror>
</mirrors>

If you are using a repository manager like Nexus for your internal repository. You can set up a proxy repository for proxy central, so any requests that would normally go to Central are instead sent to your proxy repository (or a repository group containing the proxy), and subsequent requests are cached in the internal repository manager. You can even set the proxy cache timeout to -1, so it will never request for contents from central that are already on the proxy repository.

如果您正在使用Nexus等存储库管理器作为内部存储库。您可以为代理中心设置代理存储库,因此通常转到Central的任何请求都会发送到您的代理存储库(或包含代理的存储库组),后续请求将缓存在内部存储库管理器中。您甚至可以将代理缓存超时设置为-1,因此它永远不会从代理存储库中已有的中心请求内容。


A more basic solution if you are only working with local repositories is to set the updatePolicy for the central repository to "never", this means Maven will only ever check for artifacts that aren't already in the local repository. This can then be overridden at the command line when needed by using the -U switch to force Maven to check for updates.

如果您只使用本地存储库,则更基本的解决方案是将*存储库的updatePolicy设置为“never”,这意味着Maven将只检查本地存储库中尚未存在的工件。然后,可以在需要时通过使用-U开关强制Maven检查更新,在命令行覆盖它。

You would configure the repository (in your pom or a profile in the settings.xml) as follows:

您将配置存储库(在您的pom或settings.xml中的配置文件中),如下所示:

<repository>
  <id>central</id>
  <url>http://repo1.maven.org/maven2</url>
  <updatePolicy>never</updatePolicy>
</repository>

#5


4  

Very simple :

很简单 :

In your Super POM parent or setting.xml, use

在您的Super POM父级或setting.xml中,使用

        <repository>
        <id>central</id>
        <releases>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <updatePolicy>never</updatePolicy>
        </snapshots>
        <url>http://repo1.maven.org/maven2</url>
        <layout>legacy</layout>
    </repository>

It's my tips

这是我的提示

#6


0  

I had some trouble similar to this,

我有类似的麻烦,

<repository>
    <id>java.net</id>
    <url>https://maven-repository.dev.java.net/nonav/repository</url>
    <layout>legacy</layout>
</repository>
<repository>
    <id>java.net2</id>
    <url>https://maven2-repository.dev.java.net/nonav/repository</url>
</repository>

Setting the updatePolicy to "never" did not work. Removing these repo was the way I solved it. ps: I was following this tutorial about web services (btw, probably the best tutorial for ws for java)

将updatePolicy设置为“never”不起作用。删除这些回购是我解决它的方式。 ps:我正在关注这个关于Web服务的教程(顺便说一下,可能是ws for java的最佳教程)

#1


27  

The updatePolicy tag didn't work for me. However Rich Seller mentioned that snapshots should be disabled anyways so I looked further and noticed that the extra repository that I added to my settings.xml was causing the problem actually. Adding the snapshots section to this repository in my settings.xml did the trick!

updatePolicy标记对我不起作用。但Rich Seller提到应该禁用快照,所以我进一步观察并注意到我添加到settings.xml的额外存储库实际上导致了问题。在我的settings.xml中将快照部分添加到此存储库就可以了!

<repository>
    <id>jboss</id>
    <name>JBoss Repository</name>
    <url>http://repository.jboss.com/maven2</url>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
</repository>

#2


139  

Also, you can use -o or --offline in the mvn command line which will put maven in "offline mode" so it won't check for updates. You'll get some warning about not being able to get dependencies not already in your local repo, but no big deal.

此外,您可以在mvn命令行中使用-o或--offline,这将使maven处于“脱机模式”,因此它不会检查更新。您将收到一些警告,说明无法获取本地仓库中尚未存在的依赖项,但没什么大不了的。

#3


76  

Something that is now available in maven as well is

现在在maven中也可以使用的东西是

mvn goal --no-snapshot-updates

or in short

或简而言之

mvn goal -nsu

#4


29  

Update: I should have probably started with this as your projects are SNAPSHOTs. It is part of the SNAPSHOT semantics that Maven will check for updates on each build. Being a SNAPSHOT means that it is volatile and subject to change so updates should be checked for. However it's worth pointing out that the Maven super POM configures central to have snapshots disabled, so Maven shouldn't ever check for updates for SNAPSHOTs on central unless you've overridden that in your own pom/settings.

更新:我应该从这开始,因为你的项目是SNAPSHOTs。它是SNAPSHOT语义的一部分,Maven将检查每个构建的更新。作为SNAPSHOT意味着它是易变的并且可能会发生变化,因此应该检查更新。然而,值得指出的是,Maven超级POM配置中心以禁用快照,因此Maven不应该检查*SNAPSHOT的更新,除非您在自己的pom /设置中覆盖了它。


You can configure Maven to use a mirror for the central repository, this will redirect all requests that would normally go to central to your internal repository.

您可以将Maven配置为使用镜像作为*存储库,这将重定向通常发送到内部存储库的所有请求。

In your settings.xml you would add something like this to set your internal repository as as mirror for central:

在您的settings.xml中,您将添加类似这样的内容以将内部存储库设置为*镜像:

<mirrors>
  <mirror>
    <id>ibiblio.org</id>
    <name>ibiblio Mirror of http://repo1.maven.org/maven2/</name>
    <url>http://path/to/my/repository</url>
    <mirrorOf>central</mirrorOf>
  </mirror>
</mirrors>

If you are using a repository manager like Nexus for your internal repository. You can set up a proxy repository for proxy central, so any requests that would normally go to Central are instead sent to your proxy repository (or a repository group containing the proxy), and subsequent requests are cached in the internal repository manager. You can even set the proxy cache timeout to -1, so it will never request for contents from central that are already on the proxy repository.

如果您正在使用Nexus等存储库管理器作为内部存储库。您可以为代理中心设置代理存储库,因此通常转到Central的任何请求都会发送到您的代理存储库(或包含代理的存储库组),后续请求将缓存在内部存储库管理器中。您甚至可以将代理缓存超时设置为-1,因此它永远不会从代理存储库中已有的中心请求内容。


A more basic solution if you are only working with local repositories is to set the updatePolicy for the central repository to "never", this means Maven will only ever check for artifacts that aren't already in the local repository. This can then be overridden at the command line when needed by using the -U switch to force Maven to check for updates.

如果您只使用本地存储库,则更基本的解决方案是将*存储库的updatePolicy设置为“never”,这意味着Maven将只检查本地存储库中尚未存在的工件。然后,可以在需要时通过使用-U开关强制Maven检查更新,在命令行覆盖它。

You would configure the repository (in your pom or a profile in the settings.xml) as follows:

您将配置存储库(在您的pom或settings.xml中的配置文件中),如下所示:

<repository>
  <id>central</id>
  <url>http://repo1.maven.org/maven2</url>
  <updatePolicy>never</updatePolicy>
</repository>

#5


4  

Very simple :

很简单 :

In your Super POM parent or setting.xml, use

在您的Super POM父级或setting.xml中,使用

        <repository>
        <id>central</id>
        <releases>
            <updatePolicy>never</updatePolicy>
        </releases>
        <snapshots>
            <updatePolicy>never</updatePolicy>
        </snapshots>
        <url>http://repo1.maven.org/maven2</url>
        <layout>legacy</layout>
    </repository>

It's my tips

这是我的提示

#6


0  

I had some trouble similar to this,

我有类似的麻烦,

<repository>
    <id>java.net</id>
    <url>https://maven-repository.dev.java.net/nonav/repository</url>
    <layout>legacy</layout>
</repository>
<repository>
    <id>java.net2</id>
    <url>https://maven2-repository.dev.java.net/nonav/repository</url>
</repository>

Setting the updatePolicy to "never" did not work. Removing these repo was the way I solved it. ps: I was following this tutorial about web services (btw, probably the best tutorial for ws for java)

将updatePolicy设置为“never”不起作用。删除这些回购是我解决它的方式。 ps:我正在关注这个关于Web服务的教程(顺便说一下,可能是ws for java的最佳教程)