一、Could not find method leftShift() for arguments
1. 异常背景:在执行gradle脚本(build.gradle)命令gradle -q show时出错
2. 异常详情:
FAILURE: Build failed with an exception.
* Where:
Build file 'F:\test\build.gradle' line: 2
* What went wrong:
A problem occurred evaluating root project 'test'.
> Could not find method leftShift() for arguments [build_4812tmlsh4hbu49ky5fvjmj67$_run_closure1@260d7e26] on task ':show' of type org.gradle.api.DefaultTask.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
3. 异常原因:操作符 <<
在Gradle 4.x中被弃用(deprecated),并且在Gradle 5.0 被移除(removed)
4. 解决方法:(去掉<<)将脚本
apply plugin: 'java'
task show << {
println relativePath(compileJava.destinationDir)
println relativePath(processResources.destinationDir)
}
修改为
apply plugin: 'java'
task show {
println relativePath(compileJava.destinationDir)
println relativePath(processResources.destinationDir)
}
5. 查看效果:
二、Cannot add task 'wrapper' as a task with that name already exists.
1.异常背景:在执行gradle脚本(build.gradle)命令gradle wrapper时出错
2. 异常详情:
3. 异常原因:
4. 解决方法:
将build.gradle中内容
task wrapper(type: Wrapper) {
gradleVersion = '6.2.2'
}
修改为
wrapper {
gradleVersion = '6.2.2'
}