Reputation: 1003
I'm new to gradle and I'm getting a build error that I don't really understand. My project is just an empty shell with the directory structure and no java source code. Here is my root build.gradle file
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.+'
}
when I execute the gradle build command the build fails because it doesn't know the testCompile method with this message:
Could not find method testCompile() for arguments [{group=junit, name=junit, version=4.+}] on root project
I use Gradle 2.5.
I've understood that this method is a part of the java plugin which I've loaded. I don't see what went wrong, can you help?
Upvotes: 47
Views: 53314
Reputation: 134
Please check Gradle version used in the project.
compile and testCompile configurations are removed in Gradle 7+. You can use implementation and testImplementation instead.
Upvotes: 7
Reputation: 7602
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?
Upvotes: 101
Reputation: 14197
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.+'
}
}
Upvotes: 13
Reputation: 761
It's saying that it can't find the method testCompile for the arguments check that you spelt it correctly making sure the name and group which you have as "junit" are all correct and also the version is correct another fix for this issue is adding the testCompile line in sub projects block.
Upvotes: -1