Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a dependency to the android gradle task 'test'?

I've introduced a dependency for my unit tests to a custom task I've written in gradle. In android-gradle v1.2.3 the unit test task is named test. So I assumed you add a dependency with test.dependsOn. Gradle doesn't like that.

Error:

 C:\coding\source\testapp\app\build.gradle
 Error:(30, 0) Could not find property 'test' on project ':app'.

build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.nilzor.myapplication"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
}

task myTask() {
}

test.dependsOn 'mytask' 

Where do I go wrong and how do I fix it?

like image 739
Nilzor Avatar asked May 19 '15 12:05

Nilzor


Video Answer


1 Answers

Solution: Wrap it in

afterEvaluate {
    test.dependsOn 'mytask'
}
like image 163
Nilzor Avatar answered Nov 01 '22 18:11

Nilzor