我是gradle的新手,但遇到了我不太了解的构建错误。我的项目只是一个空外壳,具有目录结构,没有Java源代码。这是我的根build.gradle文件
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.+'
}
Run Code Online (Sandbox Code Playgroud)
当我执行gradle build命令时,构建失败,因为它不知道此消息的testCompile方法:
在根项目上找不到参数[{group = junit,name = junit,version = 4. +}]的方法testCompile()
我使用Gradle 2.5。
我知道,此方法是我已加载的java插件的一部分。我看不出出了什么问题,您能帮忙吗?谢谢 !
PHP*_*ate 20
如果有人根据Could not find method testCompile()
错误来到这里,那么现在更可能的原因是您需要替换不推荐使用testCompile
的testImplementation
. 请参阅Gradle 中的实现和编译有什么区别?
Java插件仅适用于子项目,因此Java插件添加的testCompile配置只能在子项目中使用。下面的作品:
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.+'
}
}
Run Code Online (Sandbox Code Playgroud)
请检查项目中使用的Gradle版本。
在 Gradle 7+ 中删除了compile和testCompile配置。您可以改用implementation和testImplementation。
归档时间: |
|
查看次数: |
6142 次 |
最近记录: |