I am working on a big projects with many pom.xml files and I need to specify all the libraries that I use. This means that I need to read pom.xml files recursively and get groupId, artifactId, scope and version. I checked out mvn dependency:tree but I can't find a way to print it to a file in a readable format. I saw appendOutput but I saw no example on how to use it in cmd. I saw some solutions done in Linux but I only have access to Windows XP.
8 Answers
This can (at least now) be done with command line options to the dependency:tree plugin.
Try:
mvn dependency:tree -Doutput=/path/to/file
Reference: Maven Dependency Plugin Page
You only asked about "readable" format, but you can also pass the -DoutputType parameter with various options. Also note that the version I have installed, I get the following warning:
[WARNING] The parameter output is deprecated. Use outputFile instead.
So, consider trying it with -DoutputFile=/path/to/file
Also, I was unable to get the -DoutputType paramater to give me anything other than the default text, but didn't have a chance to play around with it. YMMV.

- 66,836
- 64
- 257
- 336

- 1,260
- 10
- 12
-
1-Dmdep.outputFile=/path/to/file.txt worked, all the other options didn't – niken Mar 03 '17 at 20:19
-
3As of Maven 3.5.0 and maven-dependency-plugin 2.8, `-DoutputFile=/path/to/file.txt` works with no warning. – JakeRobb Oct 30 '18 at 19:00
-
1`mvn dependency:tree` does not print transitive dependencies through the parent pom, making this unappropriate for debugging purposes – Tamas Hegedus Mar 05 '19 at 15:31
-
refs: https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html#outputFile – noanswer Apr 12 '23 at 08:36
If you have multiple modules under the same repo/project and want the dependencies of all the modules in one file, so as to be able to diff b/w one build and another to see if something changed somewhere, you can do
$project_dir> mvn dependency:tree -DoutputFile=<absolute_path_to_file> -DappendOutput=true
e.g.
$project_dir> mvn dependency:tree -DoutputFile=`pwd`/mvn_dependency_tree.txt -DappendOutput=true
See other options available at https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html

- 331
- 2
- 6
Adding the
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>depends-maven-plugin</artifactId>
</plugin>
plugin produces a classes/META-INF/maven/dependencies.properties
file with the project dependencies easily parseable.
Example of the output produced:
# Project dependencies generated by the Apache ServiceMix Maven Plugin
# Generated at: Mon Oct 10 17:43:00 CEST 2011
groupId = my.group.name
artifactId = my.artifact.name
version = 0.0.1-SNAPSHOT
my.group.name/my.artifact.name/version = 0.0.1-SNAPSHOT
# dependencies
junit/junit/version = 4.8
junit/junit/type = jar
junit/junit/scope = test
org.easymock/easymock/version = 2.4
org.easymock/easymock/type = jar
org.easymock/easymock/scope = test

- 10,206
- 7
- 48
- 58
On GNU/Linux I would just do mvn dependency:tree > myFile
. However, if you're restricted to Windows only, than I would look for Windows' syntax for streaming the output of a command.
According to this site (just a top-results from Google) it seems that Windows' console also use >
sign to direct the output stream to i.e. a file.
So would you mind trying this?

- 17,914
- 8
- 63
- 82
I have run the below command and got the file having all the maven dependency.
mvn dependency:tree -DoutputFile=temp/mvn_dependency_tree.txt
This command will create a folder named "temp" and inside this folder a file name mvn_dependency_tree.txt will be created with all the dependencies.

- 18,591
- 15
- 71
- 96

- 21
- 1
https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html#outputFile
If the project has multi modules and you want to output the dependency to a single file, use absolute path and append options.
mvn dependency:tree -DoutputFile=/abs_path/deps.txt -DappendOutput=true

- 171
- 1
- 7
You can always install MinGW and MSYS and then use the Linux examples using dependency:tree
in Windows

- 10,821
- 4
- 36
- 48
Perhaps effective-pom (in conjunction with some linux commands for saving the file) can be sufficient for your needs.

- 4,947
- 2
- 26
- 48