Friday, February 22, 2013

maven build offline




Maven has a '-o' switch which allows you to build offline:
 -o,--offline                           Work offline
Of course, you will need to have your dependencies already cached into your$HOME/.m2/repository for this to build without errors. You can load the dependencies with:
mvn dependency:go-offline
I tried this process and it doesn't seem to fully work. I did a:
rm -rf $HOME/.m2/repository
mvn dependency:go-offline       # lot of stuff downloaded
# unplugged my network
# develop stuff
mvn install                     # errors from missing plugins
What did work however is:
rm -rf $HOME/.m2/repository
mvn install                     # while still online
# unplugged my network
# develop stuff
mvn install

---- MORE ----

Mastering The Maven Command Line – Managing Dependencies

This post is the first post of a Maven-related series. It focuses on the Maven command line that can do a lot more than just mvn clean install. This first post explores the options to configure the dependency resolution like using another local repository, forcing updates, and working offline.

Offline Mode

Maven often takes a lot of time to check the potential updates of dependencies and plugins. But sometimes, you want to skip this process, either because you don’t have an Internet connection or because you know that you can safely ignore them.
Before being able to run maven in offline mode, be sure you have compiled everything at least one time online. Maven retrieves all the dependencies in your local repository. Then, the offline mode just reuses the latest retrieved artifacts.
Enabling the offline mode is quite simple:
1mvn –-offline clean install
or
1mvn –o clean install
So, to work offline:
  • run the build in online mode
  • use the --offline option

Using different settings

If you are working on different projects or for different customers, you may have several settings files. By default, maven uses a settings file located in ~/.m2/settings.xml. You can override this location in the command line with the --settings option:
1mvn --settings ~/.m2/settings-customer1.xml clean install
or
1mvn –s ~/.m2/settings-customer1.xml clean install
This second settings file can define different repositories, credentials, proxies, profiles…
Less common but still, you can override the global settings with the --global-settings parameter (or simply -gs).

Forcing updates

Working offline is sometimes interesting, but forcing updates can be useful to retrieve the latest version of a snapshot artifacts developed by one of your teammates. The --update-snapshots options (or -U) forces maven to check all snapshot dependencies and retrieve latest versions:
1mvn --update-snapshots clean install
Or
1mvn -U clean install
Thanks to this option, you’re sure to build the project against the latest available version of all your snapshot dependencies. If not used, the dependencies are checked once a day (default behavior).

Building from scratch: specifying a local repository

The last option of this blog post is not a real option but a pretty useful system variable. Before committing your changes, you want to be sure that you didn’t introduce any unavailable dependency. However, such dependencies may be in your local repository, and so you want to be sure they can still be retrieved and used.
Deleting your local maven repository completely may do the job, but … it’s not necessarily what you want.
The maven.repo.local variable allows configuring the local repository location of Maven:
1mvn clean install –Dmaven.repo.local=~/tmp/tmp-repo
This creates a complete new local repository at the specified location. In other words, you will compile your projects from scratch checking that you’re not using non-available artifacts from your (main) local repository. For sure it takes more time, but that’s the price to pay. Coupled with the --settings option (pointing to a generic settings file) you can be sure that the projects you are working on are building without any specific configuration.
---- MORE ----
http://www.sonatype.com/books/mvnref-book/reference/running-sect-options.html

No comments:

Post a Comment