Expand Authors Top

If you have a few years of experience in the Java ecosystem and you’d like to share that with the community, have a look at our Contribution Guidelines.

November Discount Launch 2022 – Top
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

November Discount Launch 2022 – TEMP TOP (NPI)
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

Expanded Audience – Frontegg – Security (partner)
announcement - icon User management is very complex, when implemented properly. No surprise here.

Not having to roll all of that out manually, but instead integrating a mature, fully-fledged solution - yeah, that makes a lot of sense.
That's basically what Frontegg is - User Management for your application. It's focused on making your app scalable, secure and enjoyable for your users.
From signup to authentication, it supports simple scenarios all the way to complex and custom application logic.

Have a look:

>> Elegant User Management, Tailor-made for B2B SaaS

1. Overview

Sometimes we may need to ask Maven explicitly to not download anything from its repositories for a variety of reasons.

In this short tutorial, we're going to see how to enable the offline mode in Maven.

2. Preparing

Before going for the offline mode, it's essential to download the necessary artifacts. Otherwise, we may fail to use this mode effectively.

In order to prepare for offline mode, we can use the go-offline goal from the maven-dependency-plugin:

mvn dependency:go-offline

This goal resolves all project dependencies — including plugins and reports and their dependencies. After running this goal, we can safely work in offline mode.

3. Offline Mode

To execute Maven goals and phases in offline mode, we just have to use the -o or –offline option. For instance, in order to run integration tests in offline mode:

mvn -o verify

This command will successfully execute all tests if we already downloaded all the required artifacts. Otherwise, it will fail.

It's also possible to configure the offline mode globally by setting the offline property in the ~/.m2/settings.xml file:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <offline>true</offline>
</settings>

This setting will be applied to all Maven projects. The offline property is by default set to false. So, when we're using the -o option, it will override that default setting temporarily for the duration of that command.

4. Conclusion

In this quick tutorial, we saw how to prepare for Maven offline mode using maven-dependency-plugin. Also, we got familiar with both a command-line approach and a settings-based approach to enable the offline mode.

November Discount Launch 2022 – Bottom
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

Maven footer banner
Comments are closed on this article!