在Gradle里访问任务(task)的几种方式
在build.gradle里定義一個(gè)hello任務(wù):
輸出:
任務(wù)也可以通過tasks集合來訪問:
println tasks.hello.name
println tasks[‘hello’].name
println ‘–’
tasks.each{ println it}
輸出:
Configure project :
hello
hello
–
task ‘:buildEnvironment’
task ‘:components’
task ‘:dependencies’
task ‘:dependencyInsight’
task ‘:dependentComponents’
task ‘:hello’
task ‘:help’
task ‘:init’
task ‘:model’
task ‘:outgoingVariants’
task ‘:prepareKotlinBuildScriptModel’
task ‘:projects’
task ‘:properties’
task ‘:tasks’
task ‘:wrapper’
另一種辦法是,使用 tasks.getByPath() 方法獲取任務(wù)路徑并且通過這個(gè)路徑來訪問任務(wù)。 getByPath() 方法支持用任務(wù)名稱,相對(duì)路徑或者是絕對(duì)路徑作為參數(shù)調(diào)用。
task hello println tasks.getByPath('hello').path println tasks.getByPath(':hello').path輸出:
要獲取更多Jerry的原創(chuàng)文章,請(qǐng)關(guān)注公眾號(hào)"汪子熙":
總結(jié)
以上是生活随笔為你收集整理的在Gradle里访问任务(task)的几种方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 英伟达晒《赛博朋克 2077》主题 RT
- 下一篇: Gradle里Copy任务(task)的