Gradle調用 Ant 任務

2020-07-24 15:44 更新

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

例子 6.13. 使用 AntBuilder 來執(zhí)行 ant.loadfile 任務

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 ***


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號