How do I prevent Maven from downloading artifacts every time?

MavenDependenciesMaven 3Dependency Management

Maven Problem Overview


I’m using Maven 3.1.1. In one of my projects, I reference another one of my projects …

    <dependencies>
            <dependency>
                    <groupId>org.mainco.subco</groupId>
                    <artifactId>myprojectA</artifactId>
                    <version>${project.version}</version>
            </dependency>

The above is dependent on a couple other of my projects. However, when I run “mvn clean install,” Maven attempts to download these artifacts instead of just using what’s in my local repository. How do I get Maven to only download things if they do not exist in my local repository? Here’s the output of what I’m seeing …

davea$ mvn clean install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building subco admin Module 57.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://download.java.net/maven/2/org/mainco/subco/myprojectA/57.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/subco/57.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/projectB/57.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/projectC/57.0.0-SNAPSHOT/maven-metadata.xml
[INFO]

Maven Solutions


Solution 1 - Maven

If you use offline flag it will use your libraries from local repo.

mvn clean install -o 

Solution 2 - Maven

You may control the update frequency by configuring repositories in the $USER_HOME/.m2/settings.xml file. Specifically, change the updatePolicy to a value that results in less frequent updates.

This Stackoverflow answer has more detail.

Solution 3 - Maven

If you want to update some jars but not the snapshots of locally installed ones you should use the -nsu (--no-snapshot-updates) flag to prevent Maven from fetching the latest snapshot from the main repository. Using -o will prevent it from fetching other upgrades and (often) essential maven jars from remote repositories.

Solution 4 - Maven

In my experience, none of that works once maven has "decided" that it must download the file from an specific server.

Configure updatePolicy a other suggest, but in order to suceed, you should go to the folder inside the local repository where the jar is, and delete a file named "_maven.repositories". Delete also al files ending in ".lastUpdated". Also "m2e-lastUpdated.properties" if you are using eclipse plugin.

Solution 5 - Maven

You can setup repositories in the

> settings.xml

file of your maven install.

Read more about it on the Maven configuration webpage.

Solution 6 - Maven

I know this sounds ridiculous ;-) But one way to do it is to set the DNS entry for the maven repositories to localhost, so it fails 100% since the host can't be resolved.

/etc/hosts
# Comment this in/out as needed.
127.0.0.1 download.java.net

Note if you don't want to use localhost, you could use one of the IPs mentioned here, for example, 254.0.0.1. These IPs are reserved for future use, and thus unused.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaveView Question on Stackoverflow
Solution 1 - MavenjayalalkView Answer on Stackoverflow
Solution 2 - Mavenuser944849View Answer on Stackoverflow
Solution 3 - MavenIan TurtonView Answer on Stackoverflow
Solution 4 - MavenRober2D2View Answer on Stackoverflow
Solution 5 - MavenLeoView Answer on Stackoverflow
Solution 6 - MavenBrad ParksView Answer on Stackoverflow