Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy Maven repository to another computer

Tags:

java

maven

Is there some index or cache that needs to be refreshed or deleted when I copy over the Maven repository from another computer?

I would like to copy the local Maven repository from my laptop for use on another computer that is effectively offline. After copying the files from ~/.m2/repository it does not work as expected. When I execute mvn package -o I get an error that it cannot find one of the artifacts from the new repository:

[ERROR] Failed to execute goal on project [...]: Could not resolve dependencies for project [...]: 
Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact com.oracle:ojdbc6:jar:11.2.0.3.0 has not been downloaded from it before.

But I do have the artifact in the folder at ~/.m2/repository/com/oracle/ojdbc6/11.2.0.3.0 that was copied in from the other computer. (This particular one is not public; it is stored on our company Nexus server which cannot be reached from the target system.)

like image 577
jcadcell Avatar asked Jul 20 '15 19:07

jcadcell


People also ask

Where is maven repository located?

Custom Local Repository in settings. That config file is located in the Maven installation directory in a folder called conf, with the name settings. xml.

What is .m2 folder in maven?

m2 folder is the default folder used by maven to store its: settings. xml file which specifies properties, like the central repository to download your dependencies, the location of the so-called localRepository. by default, the localRepository in which maven stores all the dependencies your project might need to run.


1 Answers

Maven uses the "update policy" in the settings.xml file to decide whether to download the artifact or to use the one in the local repository if available.

If you don't want Maven to update your dependencies, you should configure <updatePolicy>never</updatePolicy>. You also need to use the same repository <id>s in both locations.

So if you are only using Maven's Central Repository, your repository configuration would look something like this:

<repository>
  <id>central</id>
  <name>Maven Central</name>
  <url>https://repo1.maven.org/maven2</url>
  <releases>
    <enabled>true</enabled>
    <updatePolicy>never</updatePolicy>
    <checksumPolicy>warn</checksumPolicy>
  </releases>
  <snapshots>
    <enabled>false</enabled>
  </snapshots>
</repository>
like image 94
Stefan Ferstl Avatar answered Oct 04 '22 04:10

Stefan Ferstl