2013-07-08 41 views
6

我有一個maven多項目設置,並試圖切換到gradle。我想弄清楚如何讓一個項目的測試依賴包含另一個項目的測試jar。現在我有在項目A以下幾點:Gradle從其他項目拉測試瓶

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

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

而且在項目B我有:

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

我看到我的測試失敗進行編譯。看起來他們缺少測試jar中定義的類。當我檢查構建目錄時,我發現ProjectA-0.1.56-SNAPSHOT-tests.jar存在。

在行家我已經爲項目A以下:

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

這對於項目B:

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

我怎樣才能得到這個工作就像行家?

+1

看看這裏http://stackoverflow.com/questions/5144325/gradle-test-dependency有http://stackoverflow.com/問題/ 5644011 /多項目測試的依賴與 - 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 
相關問題