2011-10-31 18 views
26

我正在处理一个包含许多pom.xml文件的大型项目,我需要指定所有我使用的库。这意味着我需要递归读取pom.xml文件并获取groupId,artifactId,作用域和版本。我检出mvn依赖关系:树,但我找不到一种方式将其打印到文件中,其格式可读。我看到appendOutput,但我没有看到如何在cmd中使用它的例子。我在Linux中看到了一些解决方案,但我只能访问Windows XP。如何让Maven依赖项以可读格式打印到文件中?

回答

53

这可以(至少现在)用依赖项的命令行选项完成树插件。

尝试:

mvn dependency:tree -Doutput=/path/to/file 

参考:Maven Dependency Plugin Page

你只问 “可读” 的格式,但你也可以通过使用不同的选项-DoutputType参数。还要注意的是版本我已经安装了,我得到以下警告:

[WARNING] The parameter output is deprecated. Use outputFile instead. 

因此,考虑-DoutputFile = /路径/试图到/文件

而且,我无法获得 - DoutputType paramater给我默认文本以外的任何东西,但没有机会玩弄它。因人而异。

+1

-Dmdep。outputFile = – AndyS

+0

-Dmdep.outputFile =/path/to/file.txt工作,所有其他选项没有 – sloven

0

您可以随时安装MinGW and MSYS然后用使用dependency:tree Linux的例子在Windows

0

也许effective-pom(与该文件的保存一些Linux命令一起)可足以满足您的需求。

3

添加

<plugin> 
    <groupId>org.apache.servicemix.tooling</groupId> 
    <artifactId>depends-maven-plugin</artifactId> 
</plugin> 

插件产生classes/META-INF/maven/dependencies.properties文件与项目依赖便于解析。产生的输出的

实施例:

# 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 
4

在GNU/Linux的我只想做mvn dependency:tree > myFile。但是,如果仅限于Windows,则会比查找Windows的语法来传输命令的输出。

根据this site(来自Google的顶级搜索结果),Windows的控制台似乎也使用>符号来指示输出流即文件。 你会介意尝试这个吗?

+3

的命令是Windows一样的。 –

+0

>来自POSIX。在Windows中,它效果很好 – kingoleg

1

如果您在同一个repo/project下有多个模块,并且希望所有模块在一个文件中的依赖关系,以便能够区分一个构建和另一个构建,以查看某处是否发生了某些更改,则可以做

$project_dir> mvn dependency:tree -DoutputFile=<absolute_path_to_file> -DappendOutput=true 

eg

$project_dir> mvn dependency:tree -DoutputFile=`pwd`/mvn_dependency_tree.txt -DappendOutput=true 

查看可用的其他选项https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html