Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle pull test jar from other project

Tags:

maven

gradle

I have a multi-project setup in maven and trying to switch to gradle. I am trying to figure out how to have one project's test dependencies include another project's test jar. Right now i have the following in ProjectA:

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

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

And in ProjectB i have:

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

I see that my tests are failing to compile. Looks like they are missing classes defined in the test jar. When I check the build dir, i see that the ProjectA-0.1.56-SNAPSHOT-tests.jar is present.

In maven I had the following for 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>

And this for ProjectB:

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

How can I get this to work just like maven?

like image 644
ekaqu Avatar asked Jul 08 '13 09:07

ekaqu


1 Answers

What you will end up with is something like

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
like image 159
Patrick Bergner Avatar answered Sep 28 '22 02:09

Patrick Bergner