3

As described in Gradle Test Dependency and Multi-project test dependencies with gradle, the solution for cross-project test dependencies is to define something like

task testJar(type: Jar, dependsOn: testClasses) {
    from sourceSets.test.java
    classifier "tests"
}

configurations {
    tests
}

artifacts {
    tests testJar
}

in the depended-upon project and

dependencies {
    testCompile project(path: ':aProject', configuration: 'tests')
}

in the dependent project.

But the answers there mention Gradle 1.x, a few 2.x. In Gradle 3.5 this gives me

Error:(22, 0) Could not get unknown property 'testClasses' for project ':communicator-api' of type org.gradle.api.Project.

and removing the dependsOn: testClasses gives

Error:(23, 0) Could not get unknown property 'sourceSets' for task ':communicator-api:testsJar' of type org.gradle.api.tasks.bundling.Jar.

How to define testJar in Gradle 3.x or 4.x? Or is there a more standard solution now?

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • I assume that you did not apply the Java Plugin to your project because it adds both the task and the `sourceSets` container which are missing according to your error messages. – Lukas Körfer Nov 15 '17 at 23:59
  • The issue was with ordering. I was trying to do this in root project's `subprojects` to avoid code duplication, so it was happening before the Java plugin was applied. – Alexey Romanov Nov 16 '17 at 07:17
  • And apparently what I needed is `afterEvaluate`. – Alexey Romanov Nov 16 '17 at 07:22

0 Answers0