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?
The testCompile configuration contains the dependencies which are required to compile the tests of our project. This configuration contains the compiled classes of our project and the dependencies added to the compile configuration.
When building an Android project using gradle 4.1 and the android gradle plugin 3.0 a warning message is emitted when running any gradle command: Configuration 'testCompile' in project ':app' is deprecated. Use 'testImplementation' instead.
testRuntime The dependencies required to run the tests. By default, also includes the compile, runtime and test compile dependencies. Check the second part: By default, also includes the compile, runtime and test compile dependencies. It says testRuntime includes compile, runtime and testCompile.
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?
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.+' } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With