Skip to content

/flags/maven/mvn-u-update-snapshots

mvn -U: force Maven to re-check snapshots and missing artifacts

The commands on this page have not been executed by our verification runner yet.updated
tool
Maven
command
mvn
flag
-U, --update-snapshots
default
off (remote checks follow each repository's updatePolicy, daily by default)

mvn -U clean install (long form --update-snapshots) forces Maven to check the remote repositories for newer SNAPSHOT versions and to retry artifacts that previously failed to download, ignoring the update interval. Without it, Maven checks a snapshot at most once a day by default and remembers failed downloads, which produces the familiar "was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced" error. "Updates are forced" means exactly -U.

When you need it

  • A teammate deployed a new 1.4.0-SNAPSHOT of a library, but your build keeps using yesterday's copy.
  • A dependency failed to download once (network problem, wrong repository, missing credentials) and every later build fails immediately with the cached-failure message, even after the cause was fixed.
  • A plugin or dependency was published to a repository after Maven first looked for it.
bash
mvn -U clean install            # check snapshots and retry failed downloads
mvn -U dependency:tree          # see what versions resolve now
mvn -nsu clean install          # the opposite: never update snapshots in this build
OptionEffect
-U, --update-snapshotsCheck for updated snapshots and missing releases now
-nsu, --no-snapshot-updatesDo not update snapshots at all during this build
-UM, --update-metadataForce updates of repository metadata (plugin prefixes, version ranges); newer Maven releases
-UA, --update-artifactsRetry cached artifact retrieval errors; newer Maven releases
-o, --offlineNo remote access at all
updatePolicy in settings.xmlalways, daily (default), interval:MINUTES or never per repository

What -U does not do

-U does not delete or re-download released versions such as guava:33.0.0-jre: releases are immutable and stay in ~/.m2/repository. If a released artifact in the local repository is corrupt (for example a truncated jar), delete that version's folder and build again, or use mvn dependency:purge-local-repository.

It also does not change which version is chosen. If the POM asks for 1.3.0, -U will never pick 1.4.0; for newer releases see mvn versions:display-dependency-updates.

Pitfalls

  • Using -U on every local build slows it down, because every snapshot is checked against every repository. Keep it for CI or for the moment you need it.
  • The cached-failure message can hide the real cause. Run once with -U -e to see the actual download error (proxy, 401 Unauthorized, wrong URL in settings.xml).
  • Plugin prefix resolution uses repository metadata; a stale prefix cache is one reason for No plugin found for prefix, and -U refreshes it.
  • Gradle's counterpart is --refresh-dependencies.

FAQ

Does mvn -U re-download every dependency?

No. Released versions that are already in the local repository are never downloaded again. -U only makes Maven check remote repositories for newer SNAPSHOT builds and retry artifacts whose earlier download failed.

What does 'resolution will not be reattempted until the update interval has elapsed' mean?

An earlier build could not download the artifact, and Maven cached that failure in the local repository. Until the repository's update interval passes (daily by default) it will not try again; -U forces an immediate retry.

How do I make Maven always check for new snapshots?

Set <updatePolicy>always</updatePolicy> for snapshots on the repository in settings.xml or the POM. That costs a remote check on every build, so many teams prefer -U in CI only.

Sources