Gradle 入门(一)

build.gradle

=========================

defaultTasks 'loadFile'


task testTask  {
 println "begin without call...."
}
File[] fileList(String dir){
 file(dir).listFiles({file-> file.isFile()} as FileFilter).sort()
}

task myTask  << {
 println "myTask begin"
 ext.exP = "ext ppp"

task loadFile << {
 fileList('../..').each({file -> println "i am $file.name"})
}

loadFile << {
 println "again"
 println myTask.exP
}

loadFile.dependsOn myTask


==============================


output:


begin without call....
:myTask
myTask begin
:loadFile
i am android-4.3_r2.1-sources.jar
i am android-4.3_r2.1.jar
i am Building a Dynamic UI with Fragments   Android Developers.htm
i am Creating a Fragment   Android Developers.htm
i am default.html
again
ext ppp

==================================


心得:


task testTask  {
 println "begin without call...."
}  

不带 <<的task , 直接执行, 所以类似定义extra 属性的task,

要么也不要带<<, 要么通过dependsOn 来指定这个task先执行


否则定义的属性会找不到


你可能感兴趣的:(gradle,groovy,task)