Mavenは「テスト」フェーズの開始時に「依存関係:ツリー」を実行します。

StackOverflow https://stackoverflow.com//questions/12687743

  •  12-12-2019
  •  | 
  •  

質問

「テスト」フェーズの開始時に「テスト」フェーズの開始時に「依存関係:ツリー」ゴール出力を得る必要があります。

Antは簡単だったでしょう、私はここでMavenのドキュメントと数多くの答えを見ましたが、まだそれを理解することはできません、確かにそれはそれほど難しいですか?

役に立ちましたか?

解決

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>
.


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

他のヒント

これはテスト依存関係ツリーを出力します:

mvn test dependency:tree -DskipTests=true
.

プロジェクト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/はじめに/紹介-LifeCycle.html#plugins

関連項目 http://maven.apache。org / guides /序文/序論からlifecycle.html#lifecycle.html#lifecycle_reference ビルドフェーズのリスト。MABAが指摘すると、treeの目標が正しい時間に実行されるように慎重に選択する必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top