Could not find method testCompile() for arguments
错误如下:
A problem occurred evaluating root project ‘gradle-demo’.
Could not find method testCompile() for arguments [{group=junit, name=junit, version=4.12}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
最近在学习gradle,我使用的是ide的gradle创建的java项目,ide的gradle是很老的版本,其build.gradle文件的dependencies默认如下:
dependencies {
// testCompile代表的是依赖范围
testCompile group: 'junit', name: 'junit', version: '4.12'
}
创建完项目之后,我把ide切换到我下载的是最新的gradle7.2,就报了上面那个错误
在最新版本中,testCompile改为了testImplementation,所以找不到testCompile()方法,只要把testCompile改为testImplementation即可
参考gradle官网:https://docs.gradle.org/current/samples/sample_building_java_libraries.html