Gradle - add dependency on tests of another module

I have a multi-module gradle project that looks like this:

Parent
|--server
|--application (android module)
+--common

Server tests depend on general unit tests. For this, I added

testCompile files(project(':common').sourceSets.test.output.classesDi
compileTestJava.dependsOn tasks.getByPath(':common:testClasses')

and it worked great. Unfortunately, when I tried to do the same for an application module, which also has a dependency on general unit tests, this will not work. He does not work:

Build file 'application\build.gradle' line: 103
A problem occurred evaluating project ':application'.
 Could not find property 'sourceSets' on project ':common'

After playing Google, I also tried

 project.evaluationDependsOn(':common')
    testCompile files(project(':common').sourceSets.test.output.classesDir)

But with another exception:

Project application: Only Jar-type local dependencies are supported. Cannot handle: common\build\classes\test

Any ideas on how to fix this?

+8
source share
4 answers

. https://softnoise.wordpress.com/2014/09/07/gradle-sub-project-test-dependencies-in-multi-project-builds/ , , :

:

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

configurations {
    testOutput
}

artifacts {
    testOutput jarTest
}

: dependencies{ testCompile project(path: ':common', configuration: 'testOutput') }

, , ! https://plugins.gradle.org/plugin/com.github.hauner.jarTest/1.0

+16

sakis, , Android ( debug). :

task jarTests(type: Jar, dependsOn: "assembleDebugUnitTest") {
    classifier = 'tests'
    from "$buildDir/intermediates/classes/test/debug"
}
configurations {
    unitTestArtifact
}
artifacts {
    unitTestArtifact jarTests
}

:

dependencies {
    testCompile project(path: ":libName", configuration: "unitTestArtifact")
}
+3

@droidpl ?

android.productFlavors, androidTestArtifact, $ {flavour.name.capitalize()},

all { flavor ->
        task("android${flavor.name.capitalize()}TestJar", type: Jar, dependsOn: "compile${flavor.name.capitalize()}AndroidTestSources") {
            classifier = 'androidtests'
            from "$buildDir/intermediates/javac/${flavor.name}AndroidTest/compile${flavor.name.capitalize()}AndroidTestJavaWithJavac/classes"
        }
        configurations {
            androidTestArtifact
        }
        artifacts {
            androidTestArtifact android${flavor.name.capitalize()}TestJar
        }
    }
0

, , , , : Gradle

, , " " IntelliJ. . , - IntelliJ.

0

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


All Articles