How to configure Maven for offline development?

At some point, is maven required to connect to the Internet in order to be able to use it? The point is specifically in obtaining internal maven plugins for compilation, cleaning, packaging, etc.?

+107
java maven offline
Aug 29 '11 at 17:07
source share
12 answers

You can run maven offline mvn -o install . Of course, any artifacts not available in your local repository will fail. Maven is not based on distributed repositories, but they certainly make things smoother. For this reason, many stores use internal mirrors, which are gradually synchronized with central repositories.

Alternatively, mvn dependency:go-offline can be used to ensure that all of your dependencies are installed locally before you start working offline.

+147
Aug 29 '11 at 17:46
source share

If you have a computer with Internet access on your local network, you must install the local Maven repository.

I recommend Artifactory Open Source . This is what we use in our organization, it is very easy to set up.

Artifactory acts as a proxy between your build tool (Maven, Ant, Ivy, Gradle, etc.) and the outside world.

It caches remote artifacts so you don't have to download them again and again.

It blocks unwanted (and sometimes security-sensitive) external requests for internal artifacts and controls how and where artifacts are deployed, and by whom.

After setting up Artifactory, you just need to change the Maven settings.xml in the development machines:

 <?xml version="1.0" encoding="UTF-8"?> <settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <mirrors> <mirror> <mirrorOf>*</mirrorOf> <name>repo</name> <url>http://maven.yourorganization.com:8081/artifactory/repo</url> <id>repo</id> </mirror> </mirrors> <profiles> <profile> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>libs-release</name> <url>http://maven.yourorganization.com:8081/artifactory/libs-release</url> </repository> <repository> <snapshots /> <id>snapshots</id> <name>libs-snapshot</name> <url>http://maven.yourorganization.com:8081/artifactory/libs-snapshot</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>plugins-release</name> <url>http://maven.yourorganization.com:8081/artifactory/plugins-release</url> </pluginRepository> <pluginRepository> <snapshots /> <id>snapshots</id> <name>plugins-snapshot</name> <url>http://maven.yourorganization.com:8081/artifactory/plugins-snapshot</url> </pluginRepository> </pluginRepositories> <id>artifactory</id> </profile> </profiles> <activeProfiles> <activeProfile>artifactory</activeProfile> </activeProfiles> </settings> 

We used this solution because we had problems with Internet access in our development machines, and some artifacts downloaded corrupted files or did not load at all. Since then we have had no problems.

+10
Aug 29 '11 at 17:29
source share

You have two options:

1.) make changes to settings.xml add this to the first tag

 <localRepository>C:/Users/admin/.m2/repository</localRepository> 

2.) use the -o tag for an autonomous command.

 mvn -o clean install -DskipTests=true mvn -o jetty:run 
+8
Apr 17 '13 at 10:46
source share

Maven needs dependencies in your local repository. The easiest way to get them is through Internet access (or a more complex use of the other solutions presented here).

Suppose you can temporarily access the Internet, which you can prepare to go offline using the maven-dependency-plugin with its dependency: go-offline . This will upload all the dependencies of your project to your local repository (of course, changes in dependencies / plugins will require new access to the Internet / central repository).

+6
Aug 29 '11 at 20:32
source share

Unfortunately, dependency:go-offline did not work for me, since it did not cache everything, i.e. POMs and others implicitly mention dependencies.

A workaround was to specify the location of the local repository , either in the settings.xml file using <localRepository>...</localRepository> , or by running mvn with the -Dmaven.repo.local=... parameter. After the initial build of the project, all the necessary artifacts must be cached, and then you can refer to the repository location the same way when starting Maven in offline mode ( mvn -o ... ).

+4
Jan 03 '17 at 9:47 on
source share

Before going offline, you need to make sure that everything in your local repo is required when working offline. Running "mvn dependency: go-offline" for the project (s) / pom (s) that you intend to continue will reduce the effort to achieve this.

But this, as a rule, is not the whole story, because the dependency: go-offline will load only bare-assembly plugins ( go-offline / resolve-plugins does not allow all plug-in dependencies ). Thus, you need to find a way to load the deployment / testing / site plugins (and possibly others) and their dependencies in your repo.

In addition, the dependency: go-offline does not load the pom artifact itself, so you should depend on it: copy it if necessary.

Sometimes, as MaDa wrote, you don’t know what you need while being offline, which makes β€œenough” repo impossible.

In any case, if your repo is filled out correctly, you need to add "<offline> true </offline>" to the Maven's.xml settings for going offline.

Do not change the Maven (id) profile that was used to populate your repo while offline. Maven recognizes uploaded artifacts in its metadata with an "identifier" that is associated with a profile identifier.

+3
Feb 26 '14 at 16:08
source share

Does this work for you?

http://jojovedder.blogspot.com/2009/04/running-maven-offline-using-local.html

Remember to add it to your plugin repository and provide the URL wherever your repository is located.

 <repositories> <repository> <id>local</id> <url>file://D:\mavenrepo</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>local</id> <url>file://D:\mavenrepo</url> </pluginRepository> </pluginRepositories> 

If not, you may need to start a local server, for example. apache on your machines.

+2
Aug 29 '11 at 17:12
source share

or

Just use Maven storage servers like Sonatype Nexus http://www.sonatype.org/nexus/ or JFrog Artifactory https://www.jfrog.com/artifactory/ .

After one developer builds the project, the assembly by subsequent developers or Jenkins CI will not require Internet access.

The Maven repository server can also have proxies configured to access Maven Central (or the more necessary public repositories), and they can have a cynch'ed list of artifacts in the remote repositories.

+2
Apr 26 '16 at 13:10
source share

If you use IntelliJ, you can simply go to Settings β†’ Build, Run , Deploy β†’ Build Tools β†’ Maven and check / uncheck the Work offline box.

+2
Mar 16 '17 at 15:29
source share

The answer to your question directly: it does not require an Internet connection, but access to the repository on a local or local disk (use the tips from other people who posted here).

If your project is not in adulthood, this means that when POMs change quite often, offline mode will be very impractical, as you will also have to update your repository frequently. If you cannot get a copy of the repository that has everything you need, but how do you know? Usually you start the repository from scratch, and it is gradually cloned during development (on a computer connected to another repository). A copy of the public repository repo1.maven.org weighs hundreds of gigabytes, so I would not recommend brute force either.

0
Aug 29 '11 at 8:25
source share

When preparing to work offline, just run mvn dependency:go-offline

0
Jul 22 '13 at 14:17
source share

My experience shows that the -o option does not work properly and that the offline goal is far from sufficient for a complete autonomous build:

The solution I can test involves using the --legacy-local-repository maven option rather than -o (offline) and using the local repository instead of the repository

Also, I had to copy all the maven-metadata-maven2_central.xml local repo files into the maven-metadata.xml form expected by maven.

See the solution I found here .

0
Apr 28 '17 at 7:27
source share



All Articles