正如同你已經(jīng)在之前的示例里看到, 有一個短標記 $ 可以訪問一個存在的任務. 也就是說每個任務都可以作為構建腳本的屬性:
例子 6.11. 當成構建腳本的屬性來訪問一個任務
build.gradle
task hello << {
println 'Hello world!'
}
hello.doLast {
println "Greetings from the $hello.name task."
}
gradle -q hello 命令的輸出
> gradle -q hello
Hello world!
Greetings from the hello task.
這里的 name 是任務的默認屬性, 代表當前任務的名稱, 這里是 hello.
這使得代碼易于讀取, 特別是當使用了由插件(如編譯)提供的任務時尤其如此.