Gradle調(diào)用 Ant 任務(wù)

2020-07-24 15:44 更新

Ant 任務(wù)是 Gradle 的一等公民. Gradle 通過(guò) Groovy 出色的集成了 Ant 任務(wù). Groovy 自帶了一個(gè) AntBuilder. 相比于從一個(gè) build.xml 文件中使用 Ant 任務(wù), 在 Gradle 里使用 Ant 任務(wù)更為方便和強(qiáng)大. 從下面的例子中, 你可以學(xué)習(xí)如何執(zhí)行 Ant 任務(wù)以及如何訪問(wèn) ant 屬性:

例子 6.13. 使用 AntBuilder 來(lái)執(zhí)行 ant.loadfile 任務(wù)

build.gradle

task loadfile << {
    def files = file('../antLoadfileResources').listFiles().sort()
    files.each { File file ->
        if (file.isFile()) {
            ant.loadfile(srcFile: file, property: file.name)
            println " *** $file.name ***"
            println "${ant.properties[file.name]}"
        }
    }
}

gradle -q loadfile 命令的輸出

> gradle -q loadfile
*** agile.manifesto.txt ***
Individuals and interactions over processes and tools
Working software over comprehensive documentation
Customer collaboration  over contract negotiation
Responding to change over following a plan
 *** gradle.manifesto.txt ***


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)