7

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?

raja00cs
  • 151
  • 2
  • 4
  • Possible duplicate of [How to generate a graph of the dependency between all modules of a Maven project?](https://stackoverflow.com/questions/4084669/how-to-generate-a-graph-of-the-dependency-between-all-modules-of-a-maven-project) – Tomas Bjerre Jan 23 '18 at 14:33

2 Answers2

6

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.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
2

It is not easy at all. One option is using m2eclipse which has a feature called Class search. In the maven repositories view, right click a repository and enable full index. Then Navigate > Open type from maven - there you can look through all artifacts available based on java package convention.

Another option is to develop your own tool based on JarAnalyzer for instance, that will accept a JAR file and search through your local maven repository, looking for the most appropriate artifacts that satisfy the the imported packages/classes from the JAR.

lisak
  • 21,611
  • 40
  • 152
  • 243