Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

maven

maven-3

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.

like image 921
Johnny Avatar asked Jan 06 '15 12:01

Johnny


People also ask

How do I exclude a specific version of a dependency in Maven?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.

How do you exclude all transitive dependencies of a Maven dependency?

Exclude the transitive dependencyOpen the dependency POM and find the transitive dependency you want to exclude. Copy groupId and artifactId . In your project POM, underneath your active dependency, enter exclusions and using code completion paste the copied info of the dependency you want to exclude.

How do you override a transitive dependency?

How do you do this if the wrong dependency is a transitive dependency? By taking advantage of Maven's nearest definition logic, developers can override the version of a dependency by declaring it on the root pom. xml file.

How do I force Maven to redownload dependencies?

In Maven, you can use Apache Maven Dependency Plugin, goal dependency:purge-local-repository to remove the project dependencies from the local repository, and re-download it again.


1 Answers

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

like image 54
JMess Avatar answered Oct 04 '22 16:10

JMess