Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: How to find artifacts which depend on another artifact

Tags:

java

maven

Let us say, ArtifactA depends on ArtifactB and ArtifactC also depends on ArtifactB

I understand that "mvn dependency plugin" can help list the dependencies of a project/artifact.

But how about the reverse? If I want to find the list of projects/artifacts which depend on a given artifact? From the above example, given ArtifactB, I would like to get ArtifactA and ArtifactC

How can I achieve this?

like image 230
raja00cs Avatar asked Jan 20 '11 10:01

raja00cs


1 Answers

Maven can only operate on the current project, so it can only detect dependencies between from the current project (or sub-modules) to other projects (including sub-modules of the current project).

So what you can do is search for specific submodules depending on other submodules:

                      mycompany:parent
                    /                  \
         mycompany:child1       mycompany:child2
            /                 /                  \
  mycompany:grandchild1   mycompany:grandchild2   mycompany:grandchild3

This is how you can find all subprojects that have dependencies to grandchild3:

mvn validate -pl child2/grandchild3 -amd

This will run the validate phase on all projects within the current project that depend on grandchild3.

like image 123
Sean Patrick Floyd Avatar answered Oct 19 '22 02:10

Sean Patrick Floyd