How to force maven update? – Maven

Photo of author
Written By M Ibrahim
maven

Quick Fix: Execute ‘mvn clean install -U’ to force an update of snapshot dependencies. This will also update release dependencies that have never been successfully downloaded.

The Problem:

A project was imported to another computer, but the dependencies failed to download due to an internet connection crash. Maven is unable to resolve these dependencies and reports an error message. The goal is to find a solution to force Maven to update and resolve the dependencies, allowing the project to build successfully.

The Solutions:

Solution 1: Force Maven Update

To force Maven to update, use the `-U` (capital ‘U’) flag with the `mvn clean install` command. This flag forces Maven to update snapshot dependencies, and it also updates release dependencies if they have never been successfully downloaded before.

mvn clean install -U

Solution 2: Purge the Local Repository and Install Again

If your local repository is somehow mucked up for release jars as opposed to snapshots (only update snapshots), you can purge the local repo using the following command:

mvn dependency:purge-local-repository

You probably then want to clean and install again:

mvn dependency:purge-local-repository clean install

More information is available at https://maven.apache.org/plugins/maven-dependency-plugin/examples/purging-local-repository.html

Solution 3: Force update dependencies

To force Maven to update all SNAPSHOT dependencies, you can use the `-U` option. This will also update all other dependencies that have a newer version available.

If you want to update a single dependency without cleaning your local repository or using the `-U` option, you can remove the dependency from your local repository and then build your project.

For example, to update the `slf4j-api` dependency to version `1.7.1-SNAPSHOT`, you would run the following commands:

rm -rf ~/.m2/repository/org/slf4j/slf4j-api/1.7.1-SNAPSHOT
mvn compile

This will remove the dependency from your local repository and then build your project, which will download the latest version of the dependency.

Solution 4: Use the hammer method

If none of the other solutions worked, you can try the “hammer method”:

  1. Open a terminal and navigate to your user directory (e.g., `cd ~`).
  2. Run the following command to find all files named “*.lastUpdated” in the `.m2` directory and its subdirectories:
    “`
    find ~/.m2/ -name “*.lastUpdated” | xargs rm
    “`
  3. This will delete all the “.lastUpdated” files, which will force Maven to update the dependencies when you next build your project.

Solution 1: Force Maven Update

If you’re using Eclipse IDE, you can force Maven to update by following these steps:

  1. Right-click on the project in the Package Explorer and select Maven > Update Project Configuration.

  2. In the Update Project Configuration dialog box, select the Force Update of Snapshots/Releases checkbox and click OK.

This will force Maven to update all the project’s dependencies, including any snapshots or releases that have been updated since the project was last built.