我需要在“测试”阶段开始时从Maven获得"dependency:tree“目标输出,以帮助调试我需要知道使用了哪些版本的所有内容的问题。
在Ant中它会很容易,我已经看了Maven文档和这里的许多答案,但仍然不能弄明白,当然不是那么难吗?
发布于 2012-10-02 17:58:00
如果您希望确保dependency:tree在test阶段的开始阶段运行,那么您必须将原始的surefire:test目标移到dependency:tree之后执行。要做到这一点,你必须将插件按照它们应该运行的顺序放在一起。
下面是一个完整的pom.xml示例,它将maven-dependency-plugin添加到maven-surefire-plugin之前。原来的default-test被禁用,并添加一个新的custom-test,该dependency-tree将在执行后运行。
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>Q12687743</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}-${project.version}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>dependency-tree</id>
<phase>test</phase>
<goals>
<goal>tree</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<executions>
<execution>
<id>default-test</id>
<!-- Using phase none will disable the original default-test execution -->
<phase>none</phase>
</execution>
<execution>
<id>custom-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>这有点尴尬,但这就是禁用执行的方式。
发布于 2014-01-01 18:36:15
这将输出测试依赖关系树:
mvn test dependency:tree -DskipTests=true发布于 2012-10-02 17:37:14
在你的项目POM中声明:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>tree</goal>
</goals>
</execution>
</executions>
</plugin>您可以采用此模式在特定的构建阶段触发任何插件。参见http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Plugins。
有关构建阶段的列表,请参阅http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference。正如马巴指出的那样,您需要仔细选择阶段,以确保在正确的时间执行tree目标。
https://stackoverflow.com/questions/12687743
复制相似问题