其他项目的gradle pull测试罐

时间:2013-07-08 09:29:23

标签: maven gradle

我在maven中有一个多项目设置并尝试切换到gradle。我试图弄清楚如何让一个项目的测试依赖包括另一个项目的测试jar。现在我在ProjectA中有以下内容:

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

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

在ProjectB中,我有:

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

我看到我的测试无法编译。看起来他们缺少测试jar中定义的类。当我检查构建目录时,我看到ProjectA-0.1.56-SNAPSHOT-tests.jar存在。

在maven中,ProjectA有以下内容:

  <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一样工作?

1 个答案:

答案 0 :(得分: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