9

「テスト」フェーズの開始時にMavenから「dependency:tree」目標の出力を取得して、使用されているすべてのバージョンを知る必要がある問題のデバッグに役立てる必要があります。

Antでは簡単だったでしょう。Mavenのドキュメントとここにある多数の回答を調べましたが、それでも理解できません。確かにそれほど難しくはありませんか?

4

3 に答える 3

18

これにより、テスト依存関係ツリーが出力されます。

mvn test dependency:tree -DskipTests=true
于 2014-01-01T10:36:14.643 に答える
6

フェーズの最初dependency:tree実行されていることを確認したい場合は、元の目標をのに実行するように移動する必要があります。これを行うには、プラグインを実行する順序で配置する必要があります。testsurefire:testdependency:tree

の前にpom.xmlを追加する完全な例を次に示します。元のファイルは無効になり、新しいものが追加されます。これは実行後に実行されます。maven-dependency-pluginmaven-surefire-plugindefault-testcustom-testdependency-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>

少し厄介ですが、それが実行を無効にする方法です。

于 2012-10-02T09:57:59.913 に答える
4

プロジェクト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も参照してください。treemabaが指摘しているように、目標が正しい時間に実行されるように、フェーズを慎重に選択する必要があります。

于 2012-10-02T09:37:13.660 に答える