【发布时间】:2011-02-03 11:24:30
【问题描述】:
我想将依赖项的名称放在一个文本文件中,该文件分布在使用 Maven 构建的包中。
我打算使用maven组装插件生成tarball包,并使用过滤将名称放入文本文件中。
唯一的问题是,我一开始不知道如何引用依赖项。
【问题讨论】:
我想将依赖项的名称放在一个文本文件中,该文件分布在使用 Maven 构建的包中。
我打算使用maven组装插件生成tarball包,并使用过滤将名称放入文本文件中。
唯一的问题是,我一开始不知道如何引用依赖项。
【问题讨论】:
mvn dependency:resolve 似乎是您正在寻找的东西。将以下插件配置放入您的 POM 文件中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>list-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>resolve</goal>
</goals>
<configuration>
<outputFile>dependencies.txt</outputFile>
</configuration>
</execution>
</executions>
</plugin>
它会生成文件dependencies.txt,内容类似于:
The following files have been resolved:
am:amagent:jar:1.0:system
am:amclientsdk:jar:1.0:system
aopalliance:aopalliance:jar:1.0:compile
asm:asm:jar:2.2.3:compile
com.sun.jdmk:jmxtools:jar:1.2.1:compile
com.sun.jmx:jmxri:jar:1.2.1:compile
com.sun.xml.bind:jaxb-impl:jar:2.1.12:compile
com.sun.xml.fastinfoset:FastInfoset:jar:1.2.2:compile
com.sun.xml.messaging.saaj:saaj-impl:jar:1.3.2:compile
commons-lang:commons-lang:jar:2.3:compile
commons-logging:commons-logging:jar:1.1:compile
dom4j:dom4j:jar:1.6.1:compile
javax.activation:activation:jar:1.1:provided
javax.jms:jms:jar:1.1:compile
javax.mail:mail:jar:1.4:compile
javax.xml.bind:jaxb-api:jar:2.1:compile
javax.xml.soap:saaj-api:jar:1.3:compile
junit:junit:jar:4.4:test
log4j:log4j:jar:1.2.15:compile
【讨论】:
您不需要为此使用过滤,使用Maven Dependency plugin 及其dependency:tree 目标来显示此项目的依赖关系树。使用... outputFile 可选参数设置输出文件。因此配置可能如下所示:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>tree</id>
<phase>prepare-package</phase>
<goals>
<goal>tree</goal>
</goals>
<configuration>
<outputFile>${project.build.outputDirectory}/dep.txt</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
运行package 阶段将在target/classes/dep.txt 中生成依赖关系树并将其打包到工件中。调整它以满足您的需求。
【讨论】:
您可以使用maven-dependency-plugin dependency:tree 将依赖关系树输出到文件中。
【讨论】: