How to force maven update?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Run mvn clean install -U to force Maven to check remote repositories for updated snapshots and release dependencies. The -U flag (short for --update-snapshots) bypasses Maven's local cache timestamps and pulls the latest versions from your configured repositories.
Why Maven Caches Dependencies
Maven downloads dependencies once and stores them in your local repository at ~/.m2/repository. To avoid hitting remote servers on every build, Maven 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 caching behavior is efficient, but it causes problems when a SNAPSHOT dependency has been republished, a corrupted download is stuck in the local cache, or you need to verify that your build works with the latest artifacts.
The -U Flag: Force Update Snapshots
This command does three things:
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.
If you only need to resolve dependencies without building:
Clearing the Local Cache
When -U is not enough (for example, a corrupted JAR or POM in the cache), you can delete the cached artifacts manually:
After deleting, the next mvn install re-downloads everything from remote repositories. Deleting the entire ~/.m2/repository is slow on large projects (hundreds of dependencies), so target specific artifacts when possible.
Using the Dependency Plugin to Purge
Maven's dependency:purge-local-repository goal provides a more controlled approach:
This 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.
Alternatively, add -U to the Maven runner parameters:
File > Settings > Build, Execution, Deployment > Build Tools > Maven > Runner > VM Options: add -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:
Maven Update Policy Configuration
For more control over when Maven checks for updates, configure the updatePolicy in your pom.xml or settings.xml:
| 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) |
Setting updatePolicy to always in your repository configuration has the same effect as passing -U on every build, without needing to remember the flag.
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 |
Handling Resolution Failures
When Maven cannot resolve a dependency, it creates a .lastUpdated marker file in the local repository. This marker prevents Maven from retrying the failed resolution for a period. If the dependency becomes available later, Maven may still refuse to check:
This is a common source of confusion when a dependency was temporarily unavailable and Maven stops trying to download it.
Common Pitfalls
Using -U for release dependencies. The -U flag only forces updates for SNAPSHOT dependencies. Release versions (like 3.2.1) are considered immutable by Maven. If you need to re-download a release artifact, delete it from ~/.m2/repository manually.
Forgetting -U in CI/CD pipelines. CI builds that use a shared Maven cache across builds may serve stale SNAPSHOT artifacts. Either pass -U in CI or configure updatePolicy: always for snapshot repositories.
Auto-updating versions without testing. Running mvn versions:use-latest-versions blindly can introduce breaking changes. Always run your full test suite after updating dependency versions, and review changelogs for major version bumps.
Confusing -U with -u. The flag is uppercase -U. Lowercase -u is not a valid Maven option and will cause an error.
Network proxies blocking resolution. If -U does not resolve dependencies, check your ~/.m2/settings.xml for proxy configuration. Corporate networks often require proxy settings for Maven to reach remote repositories.
Summary
Force a Maven update with mvn clean install -U to bypass the local dependency cache and pull the latest SNAPSHOT artifacts. For corrupted cache entries, use dependency:purge-local-repository or manually delete artifacts from ~/.m2/repository. Configure updatePolicy in your repository settings for permanent control over update frequency. In IDE environments, use the built-in Maven refresh tools with the force-update option checked. The -U flag is your primary tool for SNAPSHOT freshness, but remember it does not affect release dependencies.

