How do I configure Maven for offline development?
You have two options for this:
1.) make changes in the settings.xml add this in first tag
<localRepository>C:/Users/admin/.m2/repository</localRepository>
2.) use the -o tag for offline command.
mvn -o clean install -DskipTests=true
mvn -o jetty:run
If you have a PC with internet access in your LAN, you should install a local Maven repository.
I recommend Artifactory Open Source. This is what we use in our organization, it is really easy to setup.
Artifactory acts as a proxy between your build tool (Maven, Ant, Ivy, Gradle etc.) and the outside world.
It caches remote artifacts so that you don’t have to download them over and over 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 Maven's 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 didn't download at all. We haven't had problems since.
Maven needs the dependencies in your local repository. The easiest way to get them is with internet access (or harder using other solutions provided here).
So assumed that you can get temporarily internet access you can prepare to go offline using the maven-dependency-plugin with its dependency:go-offline goal. This will download all your project dependencies to your local repository (of course changes in the dependencies / plugins will require new internet / central repository access).
You can run maven in offline mode mvn -o install
. Of course any artifacts not available in your local repository will fail. Maven is not predicated on distributed repositories, but they certainly make things more seamless. Its for this reason that many shops use internal mirrors that are incrementally synced with the central repos.
In addition, the mvn dependency:go-offline
can be used to ensure you have all of your dependencies installed locally before you begin to work offline.