2012-10-02 15 views
5

"テスト"フェーズの開始時にMavenから "dependency:tree"目標出力を取得して、必要な問題をデバッグするのに役立ちますすべてのバージョンが使用されているかどうかを知る Antでそれは簡単だったでしょう、私はここでMavenのドキュメントと多数の答えを見てきましたが、まだそれを理解することはできません、確かにそれは難しいことではないのですか?Mavenは "テスト"フェーズの開始時に "dependency:tree"を実行します

+0

あなたは 'Mavenの依存性-Plugin'をは' test'期に 'tree'目標を実行したいことを言っていますか? – maba

答えて

5

あなたはdependency:treetestフェーズの開始で実行されていることを確認したいなら、あなたはdependency:tree後に実施されることに元surefire:test目標を移動する必要があります。これを行うには、実行する順序でプラグインを配置する必要があります。

完全なpom.xmlの例では、maven-surefire-pluginの前にmaven-dependency-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> 

それは少しぎこちないですが、それは実行を無効にする方法です。

3

は、プロジェクトの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も参照してください。 mabaが指摘するように、正しいタイミングでtreeのゴールが確実に実行されるように、慎重にフェーズを選択する必要があります。

+0

これは実際のテストの後に 'dependency:tree'を実行します。 OPは、テストフェーズの開始時に彼はそれを実行することを望んでいると言います。 – maba

+0

良い点。代わりに、 'test-compile'や' compile'にバインドすることもできます。プラグインをフェーズにバインドする一般的なパターンを理解すれば、問題を解決するのに十分です。 (私の答えを編集した)。 –

+0

+1 'test'フェーズに' dependency:tree'を追加する方法を示しています。 'test'段階の始めに' dependency:tree'を実行する方法を示す別の答えを追加します。 – maba

6

この意志の出力テストの依存関係ツリー:

mvn test dependency:tree -DskipTests=true 
関連する問題