【问题标题】:gradle pull test jar from other projectgradle 从其他项目中提取测试 jar
【发布时间】:2013-07-05 14:00:15
【问题描述】:

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

【问题讨论】:

标签: maven gradle


【解决方案1】:

你最终会得到类似的东西

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    • 2018-05-28
    • 1970-01-01
    相关资源
    最近更新 更多