Allow locally built snapshots to override more recent remote snapshots

maven-2

We have a large multi-module maven project. With the objective of increasing development productivity, we recently started to deploy snapshots to a remote repository (via central build) and introduced maven profiles that mean users only need to check out and build a sub-set of modules and take snapshots for the rest. We have also set our update policy on remote repositories to 'never', to ensure that it is explicit when we want to update local snapshots. A typical command is thus; mvn -Pref -U clean install.

Now, in the maven reactor, the build for the modules defined in the profile works perfectly, maven using snapshots for their dependencies, including downloading any updated ones from the remote repository (important note; to ensure we have a consistent set of snapshots, our central deploy is of all module snapshots from our project, even if only a couple of them have changed).

The hitch seems to be when maven is then resolving dependencies back to those locally built modules from modules that exist outside the profile – if a snapshot has been deployed remotely since the build of such a module, then maven sees this as a more up to date version and proceeds to download and overwrite the locally built snapshot. This can cause breaks where other modules are expecting the locally changed module.

Basically I would like to have an option like 'use locally built snapshot' within any modules in my profile over any remote snapshot, even though the timestamp indicates that the remote snapshot is more recent.

What have other people done in this scenario?

thanks,

Paul

Best Answer

If you could update to Maven 3, you could use the --no-snapshot-updates command line switch (-nsu also works to save typing). There's a bug with that option that's fixed in 3.0.4, so make sure you're using the latest release.

You might also try offline mode, but that will stop ALL update checks until you stop being "offline". First, do a build to make sure you have all the dependencies downloaded to your local repository. You can then enter offline mode by adding <offline>true</offline> to your settings.xml (and switching it to false when you're ready to start checking for updates again) or using the -o or --offline command line switch when doing a build. This works in Maven 2 or 3.