How to force Maven to update dependencies (mvn clean install -U)
Codemia Knowledge Hub ·
Run mvn clean install -U to force Maven to check remote repositories for updated snapshots and for releases that previously failed to download. The -U flag (short for --update-snapshots) bypasses Maven's local cache timestamps and pulls the latest versions from your configured repositories.
Why Maven serves stale dependencies
Maven downloads dependencies once and stores them in your local repository at ~/.m2/repository. It tracks when it last checked for updates using metadata files. By default:
- Release dependencies are downloaded once and never checked again (they are considered immutable).
- SNAPSHOT dependencies are checked once per day (controlled by the
updatePolicysetting in your repository configuration).
This breaks down when a SNAPSHOT has been republished, a corrupted download is stuck in the local cache, or you need to verify the build against the latest artifacts.
The -U flag
cleandeletes thetarget/directory, removing all previous build output.installcompiles, tests, packages, and installs the artifact into your local repository.-Uforces Maven to check all remote repositories for updated SNAPSHOT versions, ignoring the daily update interval.
To resolve dependencies without building:
Clearing the local cache
When -U is not enough (for example, a corrupted JAR or POM in the cache), delete the cached artifacts:
The next mvn install re-downloads everything. Deleting all of ~/.m2/repository is slow on projects with hundreds of dependencies, so target specific artifacts when you can.
Purging with the dependency plugin
The dependency:purge-local-repository goal deletes the specified artifacts from ~/.m2/repository and immediately re-downloads them:
Forcing updates in IDEs
IntelliJ IDEA
- Open the Maven tool window (View > Tool Windows > Maven).
- Click the Reload All Maven Projects button (circular arrows icon).
- For a forced update, go to File > Invalidate Caches / Restart, then reimport the project.
Or check Always update snapshots under File > Settings > Build, Execution, Deployment > Build Tools > Maven, which makes IntelliJ check for updated snapshots every time it syncs the Maven project, much like passing -U.
Eclipse
- Right-click the project in Package Explorer.
- Select Maven > Update Project (or press
Alt+F5). - Check the Force Update of Snapshots/Releases checkbox.
- Click OK.
VS Code (with Maven for Java extension)
Open the command palette (Ctrl+Shift+P / Cmd+Shift+P) and run Maven: Update Project. To force updates, edit your settings.json:
Setting updatePolicy instead of passing -U
Configure updatePolicy in your pom.xml or settings.xml to control when Maven checks for updates:
| Update Policy | Behavior |
always | Check for updates on every build |
daily (default) | Check once per day |
interval:N | Check every N minutes |
never | Never check for updates (only use local cache) |
always has the same effect as passing -U on every build.
Command reference
| Command | What It Does | When to Use |
mvn clean install -U | Full rebuild with forced snapshot updates | SNAPSHOT dependencies may have changed |
mvn dependency:resolve -U | Resolve dependencies only, no build | Quick dependency refresh |
mvn dependency:purge-local-repository | Delete and re-download cached artifacts | Corrupted JARs, checksum failures |
mvn versions:display-dependency-updates | Show available newer versions | Planning upgrades |
mvn versions:use-latest-versions | Auto-update dependency versions in pom.xml | Automated dependency upgrades |
mvn -o clean install | Build in offline mode (no network) | Working without internet, using only cached deps |
mvn -C clean install | Strict checksum checking | Detecting corrupted downloads |
Removing .lastUpdated markers after a failed download
When Maven cannot resolve a dependency, it writes a .lastUpdated marker file in the local repository, which stops it retrying for a period. If the dependency becomes available later, Maven may still refuse to check:
This often confuses people when a dependency was temporarily unavailable.
When -U does not fix it
Release dependencies. -U only forces updates for SNAPSHOT dependencies. Release versions (like 3.2.1) are immutable to Maven. To re-download one, delete it from ~/.m2/repository manually.
CI with a shared cache. CI builds that share a Maven cache can serve stale SNAPSHOT artifacts. Pass -U in CI or set updatePolicy to always for snapshot repositories.
Auto-updating versions without testing. Running mvn versions:use-latest-versions blindly can introduce breaking changes. Run the full test suite afterwards and review changelogs for major version bumps.
-U versus -u. The flag is uppercase -U. Lowercase -u is not a valid Maven option and causes an error.
Network proxies. If -U still fails to resolve dependencies, check ~/.m2/settings.xml for proxy configuration. Corporate networks often require proxy settings for Maven to reach remote repositories.
Related reading
- How to format a duration in java? e.g format HMMSS
- How to format a Java string with leading zero?
- How to format date and time in Android?
- How to format Joda-Time DateTime to only mm/dd/yyyy?
- How to format strings in Java
- How to free memory in Java?
- How to generate a ddl creation script with a modern Spring Boot Data JPA and Hibernate setup?
- How to generate a random permutation in Java
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.