其他项目的gradle pull测试罐

eka*_*aqu 6 gradle maven

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

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

tasks.getByPath(":ProjectA:jar").dependsOn(packageTests)
Run Code Online (Sandbox Code Playgroud)

在ProjectB我有:

testCompile project(path: ':ProjectA', classifier: 'tests')
Run Code Online (Sandbox Code Playgroud)

我看到我的测试无法编译.看起来他们缺少测试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>
Run Code Online (Sandbox Code Playgroud)

这对于ProjectB来说:

<!-- Testing -->
<dependency>
  <groupId>com.example</groupId>
  <artifactId>ProjectA</artifactId>
  <version>0.1.56-SNAPSHOT</version>
  <type>test-jar</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它像maven一样工作?

Pat*_*ner 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
Run Code Online (Sandbox Code Playgroud)