1

I have seen many posts on this, but let me say that i am not trying to write a plugin. I am making a project analyser which needs to find out resolved dependencies with their path.

Given a pom.xml(in a project) i want to find out all the dependencies(transitive too) with their paths and if possible the missing dependencies too.

Getting a version independent solution would be bonus.

PS: Every answer is suggesting to use exec to run the command on cli, i am already using this and want to find a better approach of doing this.

gabber12
  • 1,114
  • 2
  • 11
  • 18
  • What do you mean exactly by missing dependencies? I would presume that the project wouldn't compile if there were dependencies that couldn't be resolved by Maven... – Makoto Feb 11 '15 at 07:14
  • so there could be local dependencies which maven wouldnt be able to resolve if the project is moved from the orignal machine right? The case of maven dependecies would only come if the project cant compile. – gabber12 Feb 11 '15 at 07:38
  • So you'd be interested in the "provided" dependencies as well then? Those are dependencies that Maven doesn't pull down from the web; it's assumed those are provided on the box it's running on. – Makoto Feb 11 '15 at 07:41
  • @gabber12 If you move from one machine to an other you should use a repository manager which solves such problem for a company. – khmarbaise Feb 11 '15 at 07:52
  • @khmarbaise ya that is a better solution but cant work in my case for political reasons. – gabber12 Feb 11 '15 at 08:32

2 Answers2

2

You could use the maven dependency plugin. The two that I have used and found very helpful I've mentioned below:

  1. dependency:tree

Displays a tree structure of the entire dependencies both direct and transitive used. Be sure to use the verbose mode.
Link

  1. dependency:list

Displays all dependencies used in a project in a list fashion. I personally do not find this that handy at times when I need to know what are transitives and which are direct for licensing purpose. But it has its place when you just need to know what you are using or detecting duplicate libraries with different versions.
Link

In addition there is also analyze, when reading the documentation it seems quite handy but I would need to try this out and I will.

  1. dependency:analyze
  • Do you mean a system call to maven through java? I am already doing that but seems to much work to parse and a non robust approach. – gabber12 Feb 11 '15 at 07:36
  • No infact a command line call. You can redirect it to a file and then some simple parsing – Nyal Fernandes Feb 11 '15 at 07:56
  • yep i meant a command line call only but parsing would be prone to changes in the plugin. I wanted a solution more on the lines to calling some apis to get dependencies or the tree. – gabber12 Feb 11 '15 at 07:58
0

Use mvn dependency:tree. For programmatic access simply use the java Process api.

http://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html

Java Process with Input/Output Stream

Also Maven plugins are simple java classes. You can download the dependency:tree plugin's code and use it/modify it to your taste.

Community
  • 1
  • 1
acsadam0404
  • 2,711
  • 1
  • 26
  • 36