Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent Maven from downloading artifacts every time?

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] 
like image 639
Dave Avatar asked Feb 24 '14 14:02

Dave


People also ask

Why is Maven downloading the Maven metadata xml every time?

Maven does this because your dependency is in a SNAPSHOT version and maven has no way to detect any changes made to that snapshot version in the repository. Release your artifact and change the version in pom. xml to that version and maven will no longer fetch the metadata file.

Why does Maven download so much?

If the dependency has its own dependencies they will be downloaded as well. This concept is known as "transitive dependency". Now, in order to "fill" the local repo maven has to download the jars to your local hard drive, that's why you see that it downloads a lot of stuff.

Where does Maven store artifacts downloaded from remote repository?

the local repository is a directory on the computer where Maven runs. It caches remote downloads and contains temporary build artifacts that you have not yet released.

Which file maintains all the artifacts information in Maven?

An artifact is apparently a directory satisfying some constraints, e.g. it must contain a file called maven-metadata. xml and a file called <artifactId>-<version>. pom .


2 Answers

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

mvn clean install -o  
like image 60
jayalalk Avatar answered Sep 22 '22 13:09

jayalalk


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.

like image 36
user944849 Avatar answered Sep 21 '22 13:09

user944849