DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Mastering Git
  • Private Remote Maven Repository With Artipie
  • How To Convert Image Files Into GIF or WebP Format Using Java
  • How To Validate Names Using Java

Trending

  • To Switch, or Not to Switch the AI Model
  • How You Clear Your HTML5 Canvas Matters
  • How to Keep AI Agents From Going Rogue Using Docker Sandbox
  • Part 2: Securing and Scaling Goose-to-Java Agent Traffic With agentgateway

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Using Maven's -U Command Line Option

Using Maven's -U Command Line Option

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

By 
Roger Hughes
·
Mar. 11, 12 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
107.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.captaindebug</groupId>
 <artifactId>build-all</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>pom</packaging>
 <name>The Build All Pom File</name>
 <description>Pom file that co-ordinates the whole build</description>
 <modules>
  <module>../dependency-injection-factory</module>
  <module>../powermock-tips</module>
  <module>../address</module>
  <module>../xml-tips-xmlbeans</module>
  <module>../xml-tips-jaxb</module>
  <module>../xml-tips-blog</module>
 </modules>
</project>

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.

Command (computing) Repository (version control) Apache Maven

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

Opinions expressed by DZone contributors are their own.

Related

  • Mastering Git
  • Private Remote Maven Repository With Artipie
  • How To Convert Image Files Into GIF or WebP Format Using Java
  • How To Validate Names Using Java

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook