我知道为什么我的依赖不起作用。 这是我的配置:
ext {
junitVersion = "4.11"
libs = [
junit : dependencies.create("junit:junit:4.11")
]
}
configure(subprojects) { subproject ->
dependencies {
testCompile(libs.junit)
}
}
我有错误:
* 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.
感谢您的帮助
最佳答案
testCompile
配置由 java
插件声明。因此,在向 testCompile
添加依赖项之前,您必须 apply plugin: "java"
到 subprojects
。
PS:libs
的声明可以简化,如马特的回答所示。 configure(subprojects) { ... }
可以简化为 subprojects { ... }
。
关于gradle - 在gradle中添加依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22700140/