How to get Maven dependencies printed to a file in a readable format?

佐手、 提交于 2019-12-03 04:19:05

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.

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

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?

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

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

Perhaps effective-pom (in conjunction with some linux commands for saving the file) can be sufficient for your needs.

Abhishek Pandey

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!