Gradle项目运行报错Could not find method XXX及解决方案

Could not find method testCompile() for arguments

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.13.1'
}

原因是较新版的gradle将testCompile换成了testImplementation,因此换一下就好:

dependencies {
    testImplementation group: 'junit', name: 'junit', version: '4.13.1'

Could not find method compile() for arguments

dependencies {
    compile group: 'commons-io', name: 'commons-io', version: '2.6'
}

有人说报错原因是因为每一个compile声明之间应该用换行符隔开,可以先试试能不能解决问题。
在gradle官网输入关键字:
Gradle官网
Gradle项目运行报错Could not find method XXX及解决方案_第1张图片

会发现出现这类问题都是这种依赖配置写法在新版本中被移除了。
Gradle项目运行报错Could not find method XXX及解决方案_第2张图片

根据提示点进去会发现将compile关键字改一下就好:

dependencies {
    implementation group: 'commons-io', name: 'commons-io', version: '2.6'
}

遇到这类问题去官网查比在csdn查更容易解决问题。

你可能感兴趣的:(Java,gradle,java,bug)