2011-08-09 42 views
9

src/main/javaとsrc/test/java構造のプロジェクトがあり、maven-jar-pluginを使ってテストブランチのjarファイルを構築しました。しかし、すべての依存関係が解決されるようにテストjarをパッケージ化したい。依存関係を含むようにmaven-jar-pluginに伝える方法はありますか?テストJARにMavenの依存関係を含めるにはどうしたらいいですか?

ありがとうございます!

フランクは

+0

あなたの質問は不明です。すべてのテスト依存関係をテストjarに含めるか、テストデプスとして正しく解決しますか? –

+0

私はテストjarに依存関係を追加したいので、テストjarでクラスを呼び出すことができ、クラスパスには他のjarは必要ありません。 – Frank

+0

[maven-assembly-plugin](http://maven.apache.org/plugins/maven-assembly-plugin/)は、あなたが望むものを実現する方法を提供します。 –

答えて

0

同様の状況で、テストコードを別のjarに移動して元のものに依存させました。アグリゲータープロジェクトを使用して、メインjarをビルドするときにテストが実行されるようにすることができます。

+0

実際には、Hadoopで実行できる単体テストがhadoop jar myMainClassで実行されるように、JarファイルをHadoopに渡す必要があります。現在、単体テストで行使されている瓶のクラスでは見つかりませんでした... – Frank

2

あなたはこれを行うことができます:assembly pluginとジャーアセンブリを作成し、展開の依存関係を持って、新しいテストジャーをパックし、原子炉に取り付けます。あなたは終わった。

パッケージの記述子はthisのようになります。

+0

それはうまくいきませんでした。 jarファイルは以前と同じ大きさですが、NoClassDefFoundError例外を除いてメインクラスを実行することはできません。私はタールを見ましたが、確かにそれは問題のクラスを含んでいません。何か案が? – Frank

+0

申し訳ありませんが、私はあなたの要求を誤解しました。私の編集を参照してください。 –

+0

私は "パッキング"と "リアクター"が何であるかを知る必要があります。私は非常に最近、Mavenを始めました:-)あなたの助けをありがとう。 – Frank

21

Hadoopで実行する必要のある統合テストで同様の問題が発生しました。私たちの統合テストは別の統合テストモジュールのtestフォルダにありますので、必要なのはtest-jar-with-dependenciesで、私たちの生活を楽にします。

私はassembly pluginをMichael-Oの言葉通り使用しています。私のアセンブリ・ディスクリプタはsrc/main/assembly/test-jar-with-dependencies.xmlに位置し、プラグインの一部の標準jar-with-dependencies記述の修正です:このアセンブリはtest-jarに依存している

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> 
    <id>test-jar-with-dependencies</id> 
    <formats> 
     <format>jar</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <dependencySets> 
     <dependencySet> 
      <outputDirectory>/</outputDirectory> 
      <useProjectArtifact>true</useProjectArtifact> 
      <!-- we're creating the test-jar as an attachement --> 
      <useProjectAttachments>true</useProjectAttachments> 
      <unpack>true</unpack> 
      <scope>test</scope> 
     </dependencySet> 
    </dependencySets> 
</assembly> 

は、モジュールのビルドの一部として作成されています。だから私は、モジュールのpom.xmlに次を追加しました:

<!-- create a complete jar for testing in other environments --> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId>      
    <artifactId>maven-jar-plugin</artifactId> 
    <executions> 
     <execution> 
      <goals> 
       <goal>test-jar</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <configuration> 
     <descriptors> 
      <descriptor>src/main/assembly/test-jar-with-dependencies.xml</descriptor> 
     </descriptors> 
    </configuration> 
    <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>single</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
+0

これは受け入れられた解決策でなければなりません! – Ichthyo

0
<dependency> 
     <groupId>me.wener.xxx</groupId> 
     <artifactId>xxx-core</artifactId> 
     <version>${xxx.version}</version> 
     <type>test-jar</type> 
     <!-- <scope>test</scope> --> 
    </dependency> 

私はテストjar.the重要な行を含めるためにこれを使用する.Iが、これは何が必要であることを確認していない<type>test-jar</type>です。

3年前ですが、他人を助けるかもしれません。少なくとも、それは私を助けました。 :-)

+0

質問は、テストジャーを使用する方法についてではなく、それは1つを作成する方法についてです –

0

怒鳴るようアセンブリdebendencySetのフィルタを含む指定し、あなたのアセンブリ内のテスト-jarファイルの依存関係を含める:

... 
<dependencySet> 
    <outputDirectory>/</outputDirectory> 
    <includes> 
     <include>*:jar:*</include> 
     <include>*:test-jar:*</include> 
    </includes> 
</dependencySet> 
... 
0

のMaven 3

のpom.xml

のために働い以下
<plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.6</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>test-jar</goal> 
        </goals> 
        <phase>test-compile</phase> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 

アセンブリファイル

<dependencySet> 
     <outputDirectory>demo/test-lib</outputDirectory> 
     <includes> 
      <!--test only dependencies (like netty)-->  
      <include>io.netty:netty-all</include> 
      <!-- the actual test jar--> 
      <include>${project.groupId}:${project.artifactId}:test-jar</include> 
     </includes> 
     <useProjectAttachments>true</useProjectAttachments> 
     <scope>test</scope> 
    </dependencySet> 
+0

メモに余分な Ori

関連する問題