4
mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:tree -DoutputFile=/tmp/dependencies.txt -DoutputType=dot -DappendOutput=true

I'm using the above command to get a list of dependencies i.e the direct and transitive dependencies. I want an alteration in the above command which would give me a list of only the direct dependencies and ignore all the transitive dependencies. I don't want to use any other command nor do i want to change the output file format. Our parsers are dependent on the output file format. Does anyone have any solution for this?

mle
  • 2,466
  • 1
  • 19
  • 25
  • So just to be sure, you do not want to use `grep` or any other `bash` helpers? – mle Apr 17 '19 at 16:01
  • 1
    The usual way to go would be to use `dependency:list` instead of `dependency:tree`. – J Fabian Meier Apr 17 '19 at 19:53
  • The list command generates the file in an entirely different format which is not desired as far as our parsers are concerned. I see that there is an option to exclude stuff in the tree command. However, i dont see an option as to how can i exclude transitives – Yusuf Zainee Apr 18 '19 at 12:06
  • Mle, if there is no direct option, then we have no other choice other than modifying the generated file either using grep or using some python functions to exclude transitives – Yusuf Zainee Apr 18 '19 at 12:07

1 Answers1

2

I think the excludeTransitive property is what you want.

Oh, sorry, strike that, that property is only for dependency:list, not dependency:tree.

If you were willing to live with a format change, you'd want...

mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:list -DoutputFile=/tmp/dependencies.txt -DexcludeTransitive=true
Matt Sheppard
  • 116,545
  • 46
  • 111
  • 131
  • What if for some reason you get a `java.net.UnknownHostException` while trying to resolve a dependency which causes an overall failure, is there a way to ignore this? At the end of the day I just need the information concerning these dependencies (namely name and version) but I don't want to parse the pom.xml raw and do any given interpolations myself. – n1nsa1d00 Nov 10 '21 at 10:42