Is it possible to speed up maven artifacts downloading?

后端 未结 5 1248
刺人心
刺人心 2021-01-04 01:16

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? A

相关标签:
5条回答
  • 2021-01-04 01:59

    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:

    -Dmaven.artifact.threads=30

    Source: 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
    
    0 讨论(0)
  • 2021-01-04 01:59

    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!!!

    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.

    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-537 and is resolved since maven 3.6.1, see https://maven.apache.org/docs/3.6.1/release-notes.html and 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.

    0 讨论(0)
  • 2021-01-04 02:02

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

    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

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

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

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

    0 讨论(0)
  • 2021-01-04 02:06

    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:

    • Archiva: http://archiva.apache.org/
    • Artifactory: http://www.jfrog.org/
    • Nexus: http://www.sonatype.org/nexus/

    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.

    0 讨论(0)
  • 2021-01-04 02:13

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

    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.

    0 讨论(0)
提交回复
热议问题