Search code examples
mavenmaven-3

Maven force update only for specific dependency (mvn -U for selected dependencies)


The command mvn -U forcing all project dependencies to get updated from remote repository.

Is it possible to force such update for specific selection of dependencies, by explicit selection / by some logic?

The reasoning:

I don't want to force checking all the dependencies we have because how time consuming it is. All I need, is to verify a few of them or even specify only one dependency. So, such solution is highly desired.


Solution

  • There are two maven plugins that may help you here.

    The first, dependency, will simply download the given version of a dependency: mvn dependency:get -Dartifact=groupId:artifactId:version

    The second, versions, offers some behaviors which you may also find helpful.

    By running mvn versions:use-latest-releases -Dincludes=groupId:artifactId your project's pom will be updated with the latest release version of the dependency specified by the '-Dincludes' flag. You could then run the first command to download the version now referenced by your pom.

    Both of these behaviors can be heavily customized and automated to do some quite awesome things. To get more help on a plugin goal, run: mvn plugin:help -Ddetail=true -Dgoal=goal

    Example: mvn versions:help -Ddetail=true -Dgoal=use-latest-releases

    For further information: versions, dependency, and plugins