Over a million developers have joined DZone.

Using Maven's -U Command Line Option

My prefered solution was to use the Maven ‘update snapshots’ command line argument.

· Java Zone

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

In my experience when working on a multi-model project, the developers on that project tend to grab hold of all the project’s source code and build it all using some kind of Maven build-all POM project. You know the sort of thing I mean: a build-all module is a module that contains a list of other modules that get built is a specific order. I use one to build the CaptainDebug github samples and it looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <name>The Build All Pom File</name>
 <description>Pom file that co-ordinates the whole build</description>

More recently I was working on a project that was organised slightly differently and which relied heavily upon a company wide Maven “remote” repository. The idea here was that developer A worked on Project A. When he/she was happy that the code was okay, it was deployed to the repository for use by other developers. So far, so good. Problems arose when Maven snapshots were used and the snapshot artefacts were modified often.

Developer A would build their project and deploy it to the Maven repository as a snapshot. Developer B would need this latest update for their project, but their build would fail as the required JAR was not automatically downloaded from the remote repository to their local repository and they would be stuck with an old build.

The cause may have been a problem in the way the repository was configured, or a bug somewhere, or even the way Maven is supposed to work, but the fact that developers couldn’t automatically get hold of the right versions of artifacts did cause some unnecessary aggravation and lost time for all concerned.

The fix is, once you’ve discovered it, simple. You can either delete your local repository to force its rebuild, or you can start using proper Maven version numbers instead of snapshots and do the versioning yourself. This is more effort than it’s worth as developers have to talk to one another, sending out unnecessary emails etc.

My prefered solution was to use the Maven ‘update snapshots’ command line argument. To use this argument add either --update-snapshots or -U to your command line. For example:

mvn install -U


Once added, this command line arg forces Maven to check all snapshots in a remote repository and update your local repository if it’s out of date.

1The remote repository in this case was Apache Archiva although I prefer Artifactory.

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

java ,tips and tricks ,build automation

Published at DZone with permission of Roger Hughes, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}