1

We have a multi-module maven project. I have a use case where I want to know to get a list of all the dependencies which is being used in code with version:

  1. If its declared in pom and being used.
  2. Not declared in pom but still being used (transitively imported).

Bonus would be if the approach can exclude the deps which are being declared in pom but not being used in the code.

Please suggest the best way to achieve this. TIA.

bewithaman
  • 768
  • 8
  • 16
  • Does this answer your question? [How to get a list of maven dependencies and the repositories they were fetched from](https://stackoverflow.com/questions/39027312/how-to-get-a-list-of-maven-dependencies-and-the-repositories-they-were-fetched-f) – PiRocks Aug 09 '20 at 20:54

2 Answers2

2

Just use the mvn dependency:tree command.

Tobias Miosczka
  • 213
  • 2
  • 8
  • it's not working correctly at the module level. I ran it for one low level module and it printed a transitive dependency which was not being used in that module but some other higher level module. – bewithaman Aug 10 '20 at 07:57
2

There's the Maven Dependency Plugin:

The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location.

with its tree goal:

Displays the dependency tree for this project.

Regarding your bonus there's the analyze goal:

analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused and declared.

and the analyze-only goal:

is the same as analyze, but is meant to be bound in a pom. It does not fork the build and execute test-compile.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • it's not working correctly at the module level. I ran it for one low level module and it printed a transitive dependency which was not being used in that module but some other higher level module. – bewithaman Aug 10 '20 at 07:57
  • @bewithaman Can't say anything further. Didn't use it for a long time and don't know your environment, of course. If it is, it is a topic for another question. – Gerold Broser Aug 10 '20 at 09:16