Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build error with gradle Could not find method testCompile()

Tags:

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?

like image 415
Jib'z Avatar asked Jul 14 '16 23:07

Jib'z


People also ask

What is testCompile in Gradle?

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.

Is testCompile deprecated?

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.

What is testRuntime in Gradle?

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.


2 Answers

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?

like image 109
PHPirate Avatar answered Sep 19 '22 09:09

PHPirate


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.+'     } } 
like image 22
Nicolas Modrzyk Avatar answered Sep 20 '22 09:09

Nicolas Modrzyk