2013-07-08 9 views
6

私はmavenでマルチプロジェクトの設定をしていて、gradleに切り替えようとしています。あるプロジェクトのテスト依存関係に別のプロジェクトのテスト・ジャーを含める方法を理解しようとしています。今私はPROJECTAに次き:他のプロジェクトのgradle pull test jar

packageTests = task packageTests(type: Jar) { 
    classifier = 'tests' 
    from sourceSets.test.output 
} 

tasks.getByPath(":ProjectA:jar").dependsOn(packageTests) 

とProjectBの中に私が持っている:

testCompile project(path: ':ProjectA', classifier: 'tests') 

私は私のテストはコンパイルに失敗していることがわかります。テストジャーで定義されたクラスが見つからないように見えます。ビルドディレクトリをチェックすると、ProjectA-0.1.56-SNAPSHOT-tests.jarが存在することがわかります。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-jar-plugin</artifactId> 
    <version>2.4</version> 
    <executions> 
     <execution> 
     <phase>package</phase> 
     <goals> 
      <goal>test-jar</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 

そしてこのProjectBのために:

<!-- Testing --> 
<dependency> 
    <groupId>com.example</groupId> 
    <artifactId>ProjectA</artifactId> 
    <version>0.1.56-SNAPSHOT</version> 
    <type>test-jar</type> 
</dependency> 

は、どのように私はこれがちょうどMavenのように動作するように取得することができ達人で

私はPROJECTAのために、以下の持っていましたか?あなたがで終わるだろう何

+1

のようなものは、こちらをご覧くださいhttp://stackoverflow.com/questions/5144325/gradle-test-dependency、そこhttp://stackoverflow.com/あります質問/ 5644011/multi-project-test-dependencies-with-gradle – Efthymis

答えて

2

tasks.create([ 
    name: 'testJar', 
    type: Jar, 
    group: 'build', 
    description: 'Assembles a jar archive containing the test classes.', 
    dependsOn: tasks.testClasses 
]) { 
    manifest = tasks.jar.manifest 
    classifier = 'tests' 
    from sourceSets.test.output 
} 

// for test dependencies between modules 
// usage: testCompile project(path: ':module', configuration: 'testFixtures') 
configurations { testFixtures { extendsFrom testRuntime } } 

artifacts { 
    archives testJar 
    testFixtures testJar 
} 

tasks.uploadArchives.dependsOn testJar 
関連する問題