java 是否可以加快 Maven 工件的下载速度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9974311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 23:07:15  来源:igfitidea点击:

Is it possible to speed up maven artifacts downloading?

javamaven

提问by denys

Unfortunately the maven initial build is very slow due to artifacts downloading
f.e. I've tried to download the same jar using curl - it is 3 times faster!!!
Why? And how I can speed up it? Maybe maven has some config keys related to artifacts downloading speed?

不幸的是,maven 初始构建非常慢,因为
我尝试使用 curl 下载相同的 jar - 它快了 3 倍!!!
为什么?我怎样才能加快速度?也许 maven 有一些与工件下载速度相关的配置键?

Thank you.

谢谢你。

采纳答案by nwinkler

Use a local repository manager/mirror/proxy. All downloads will then go against this instead against the public repositories on the internet. The most popular ones are:

使用本地存储库管理器/镜像/代理。然后,所有下载都将与此相反,而不是与 Internet 上的公共存储库相反。最受欢迎的是:

They are fairly easy to install and set up and provide a lot of value. Most of them have free versions as well. Just use an old development box to get started and move to a real server once you want to broaden the scope and make it available to more people.

它们相当容易安装和设置,并提供了很多价值。他们中的大多数也有免费版本。一旦您想扩大范围并使其可供更多人使用,只需使用旧的开发盒即可开始并转移到真正的服务器。

回答by mushipao

I know its an old question, but stumbled here from Google. I already had proxy in place, just needed to speed up with concurrent downloads. You can using mvn option:

我知道这是一个老问题,但从谷歌这里偶然发现。我已经有了代理,只需要加快并发下载速度。您可以使用 mvn 选项:

-Dmaven.artifact.threads=30

-Dmaven.artifact.threads=30

Source: https://maven.apache.org/guides/mini/guide-configuring-maven.html

来源:https: //maven.apache.org/guides/mini/guide-configuring-maven.html

Configuring Parallel Artifact Resolution
By default, Maven 2.1.0+ will download up to 5 artifacts (from different groups) at once. To change the size of the thread pool, start Maven using -Dmaven.artifact.threads. For example, to only download single artifacts at a time:

mvn -Dmaven.artifact.threads=1 verify
You may wish to set this option permanently, in which case you can use the MAVEN_OPTS environment variable. For example:

export MAVEN_OPTS=-Dmaven.artifact.threads=3

回答by Olaf

The key point of the question was missed in the answers above:

上面的答案遗漏了问题的关键点:

I've tried to download the same jar using curl - it is 3 times faster!!!

我尝试使用 curl 下载同一个 jar - 它快了 3 倍!!!

This means it is a software issue, mitigation by installing a local proxy or altering the snapshot policy in the settings.xml both come with extra work and potential side effects, such as snapshot dependencies not being updated.

这意味着这是一个软件问题,通过安装本地代理或更改 settings.xml 中的快照策略来缓解,两者都会带来额外的工作和潜在的副作用,例如未更新快照依赖项。

The issue described by the question is maven not utilizing the available bandwidth, thus being slow. This issue was identified in https://issues.apache.org/jira/browse/WAGON-537and is resolved since maven 3.6.1, see https://maven.apache.org/docs/3.6.1/release-notes.htmland https://issues.apache.org/jira/browse/MNG-6591, respectively. There is thus no need to do anything else but update to the latest maven version.

问题描述的问题是 Maven 没有利用可用带宽,因此速度很慢。此问题已在https://issues.apache.org/jira/browse/WAGON-537中确定,并自 maven 3.6.1 以来已解决,请参阅https://maven.apache.org/docs/3.6.1/release- notes.htmlhttps://issues.apache.org/jira/browse/MNG-6591分别。因此,除了更新到最新的 maven 版本之外,无需执行任何其他操作。

回答by Garbage

You can download artifact using curl (if you think that is faster) and install it to your maven repository using following command:

您可以使用 curl 下载工件(如果您认为它更快)并使用以下命令将其安装到您的 Maven 存储库中:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
    -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Once you install it in local repository, next time maven will pick it up from there and will not try to download again.

一旦你将它安装在本地存储库中,下次 maven 将从那里获取它并且不会再次尝试下载。

Additionally, if the central maven repository site is slower to you, please consider using Maven Repository Mirrors.

此外,如果中央 Maven 存储库站点对您来说较慢,请考虑使用 Maven 存储库镜像。

Guide to Mirror Settings - http://maven.apache.org/guides/mini/guide-mirror-settings.html

镜像设置指南 - http://maven.apache.org/guides/mini/guide-mirror-settings.html

回答by FrVaBe

The best optimization is to avoid downloading. Have a look to your settings.xmlmaven configuration and check if the updatePolicyflag is set to "daily" on releasesand snapshots. This should be the default but sometimes it may be set to 'always' - e.g. in repository manager configurations.

最好的优化是避免下载。查看您的settings.xmlMaven 配置,并检查是否在发布快照上将updatePolicy标志设置为“每日” 。这应该是默认值,但有时它可能被设置为“总是”——例如在存储库管理器配置中。

Caution: In this case (daily) you have to be cautious on snapshot changes that you might not get immediatly.

注意:在这种情况下(每天),您必须对可能无法立即获得的快照更改保持谨慎。

I know that this is not a direct answer to your question but the best maven download optimization I know.

我知道这不是对您问题的直接回答,而是我所知道的最好的 Maven 下载优化。