Gradle pull test jar from another project

I have a multi-project setup in maven and try to switch to gradle. I am trying to figure out how to have one dependency on a project, including another trial bank of the project. 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 do not compile. It looks like they are missing classes defined in the test bank. When I check the build directory, I see that 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 is 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 make this work just like maven?

+6
source share
1 answer

What you get 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 
+2
source

Source: https://habr.com/ru/post/948929/


All Articles