首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maven在"test“阶段开始时运行"dependency:tree”

Maven在"test“阶段开始时运行"dependency:tree”
EN

Stack Overflow用户
提问于 2012-10-02 17:26:55
回答 3查看 6.8K关注 0票数 8

我需要在“测试”阶段开始时从Maven获得"dependency:tree“目标输出,以帮助调试我需要知道使用了哪些版本的所有内容的问题。

在Ant中它会很容易,我已经看了Maven文档和这里的许多答案,但仍然不能弄明白,当然不是那么难吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-10-02 17:58:00

如果您希望确保dependency:treetest阶段的开始阶段运行,那么您必须将原始的surefire:test目标移到dependency:tree之后执行。要做到这一点,你必须将插件按照它们应该运行的顺序放在一起。

下面是一个完整的pom.xml示例,它将maven-dependency-plugin添加到maven-surefire-plugin之前。原来的default-test被禁用,并添加一个新的custom-test,该dependency-tree将在执行后运行。

代码语言:javascript
复制
<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>

这有点尴尬,但这就是禁用执行的方式。

票数 6
EN

Stack Overflow用户

发布于 2014-01-01 18:36:15

这将输出测试依赖关系树:

代码语言:javascript
复制
mvn test dependency:tree -DskipTests=true
票数 17
EN

Stack Overflow用户

发布于 2012-10-02 17:37:14

在你的项目POM中声明:

代码语言:javascript
复制
 <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目标。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12687743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档