Build error with gradle Could not find method testCompile()

The java plugin is only applied to subprojects, so the testCompile configuration, added by the java plugin, can only be used in subprojects. The below works:

allprojects {
    //Put instructions for all projects
    task hello << { task -> println "I'm $task.project.name" }
}

subprojects {
    //Put instructions for each sub project
    apply plugin: "java"
    repositories {
        mavenCentral()
    }



    dependencies {
        testCompile group: 'junit', name: 'junit', version: '4.+'
    }
}

In case anyone comes here based on the Could not find method testCompile() error, by now the more probable cause is that you need to replace the deprecated testCompile by testImplementation. See What's the difference between implementation and compile in Gradle?

Tags:

Java

Gradle