Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow locally built snapshots to override more recent remote snapshots

Tags:

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

like image 843
Paul Watson Avatar asked Aug 26 '11 14:08

Paul Watson


People also ask

What argument do you pass to Maven in order to update snapshots from the remote repository?

Maven follows the repository's updatePolicy , which tells it how often (if ever) maven checks if a dependency has been updated (in the case of SNAPSHOT), or has become available, in the case of a released version.

How often maven should check for a newer snapshot artifact in the remote repository?

Artifacts with a newer timestamp take precedence no matter where they come from. With the default settings "remote timestamps" are checked only once every 24 hrs.

What is a snapshot build?

A "snapshot" is a build which can be replaced by another build which has the same name. It implies that the build could change at any time and is still under active development. You have different artifacts for different builds based on the same code.

What does force update of snapshots releases do?

At this time, the season MM configuration for the module A 2.1-SNAPSHOT version of the dependency, when she component module B, Maven will automatically check from the warehouse module A 2.1-SNAPSHOT the latest component, when found to be updated when the download The By default, Maven checks an update every day ( ...


2 Answers

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.

like image 86
DuckPuppy Avatar answered Oct 14 '22 23:10

DuckPuppy


I think you would have to prevent unchanged snapshots from being deployed. Deploying a snapshot is basically saying:

"this is now the latest and greatest snapshot, choose me over older (in the sense of timestamp) snapshots"

I guess you could do some jiggery-pokery to your local snapshots, such as link some script to the install phase that sets the snapshot's timestamp meta-data in the far future (so Maven always chooses local over remote snapshot). But that doesn't sound good to me at all!

Snapshot deployments can be triggered by source control commits. Can you do this instead?

like image 34
Paul Grime Avatar answered Oct 14 '22 22:10

Paul Grime