Add dependency in gradle

gradle, gradlew

Solution

The `testCompile` configuration is declared by the `java` plugin. So before you can add dependencies to `testCompile`, you'll have to `apply plugin: "java"` to `subprojects`.

PS: The declaration of `libs` can be simplified as shown in Matt's answer. `configure(subprojects) { ... }` can be simplified to `subprojects { ... }`.

Problem

I have got any idea why my dependency not working. This is my configuration: ``` ext { junitVersion = "4.11" libs = [ junit : dependencies.create("junit:junit:4.11") ] } configure(subprojects) { subproject -> dependencies { testCompile(libs.junit) } } ``` i have got error : ``` * What went wrong: A problem occurred evaluating root project 'unit590'. > Could not find method testCompile() for arguments [DefaultExternalModuleDependency{group='junit', name='junit', version='4.11', configuration='default'}] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@785c1069. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. ``` Thanks for any help

Original source