我需要在"测试"阶段开始时从Maven获取"依赖:树"目标输出,以帮助调试我需要知道所使用的所有版本的问题.
在Ant中它本来很简单,我已经浏览了Maven文档和这里的大量答案,但仍然无法弄明白,当然不是那么难吗?
tra*_*ask 13
这将输出测试依赖树:
mvn test dependency:tree -DskipTests=true
Run Code Online (Sandbox Code Playgroud)
如果你想确保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>
Run Code Online (Sandbox Code Playgroud)
这有点尴尬,但这是禁用执行的方法.
在您的项目 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>
Run Code Online (Sandbox Code Playgroud)
您可以采用此模式在特定构建阶段触发任何插件。请参阅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
在正确的时间执行。
归档时间: |
|
查看次数: |
4384 次 |
最近记录: |