1
我有一個簡約的build.gradle
文件,其中包含good
和bad
任務。我想明白爲什麼這個不行,給我一個奇怪的錯誤:從任務引用全局變量會殺死我的gradle任務
def owner = 1
task('bad') {
doLast {
println "My owner is, ${owner}"
}
}
task good {
doLast {
println 'This is good'
}
}
這是輸出:
FAILURE: Build failed with an exception.
* Where:
Build file 'test\build.gradle' line: 4
* What went wrong:
A problem occurred evaluating root project 'test'.
> No signature of method: build_6t4ha87o2gnjb2kllhp0wwfpi$_run_closure1.doLast() is applicable for argument types: (build_6t4ha87o2gnjb2kllhp0wwfpi$_run_closure
1$_closure4) values: [[email protected]]
Possible solutions: doCall(), doCall(java.lang.Object), collect(), collect(), isCase(java.lang.Object), isCase(java.lang.Object)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
但是簡單地從println的去除參考owner
甚至只重命名我的全球owner
變量爲owner1
的作品。看起來我正在干擾一些gradle內部,但不完全確定如何。
我在這個實驗中使用了gradle 3.4。