Gradle極簡筆記(一)

在命令行中使用Gradle

示例腳本

task compile {
    doLast {
        println 'compiling source'
    }
}

task compileTest(dependsOn: compile) {
    doLast {
        println 'compiling unit tests'
    }
}

task test(dependsOn: [compile, compileTest]) {
    doLast {
        println 'running unit tests'
    }
}

task dist(dependsOn: [compile, test]) {
    doLast {
        println 'building the distribution'
    }
}

執(zhí)行任務(wù):

gradle dist

排除某個任務(wù)

gradle dist -x test

用簡寫的任務(wù)名稱

gradle di

只要以“di”開頭的任務(wù)只有一個,就可以這樣執(zhí)行,不一定非得是任務(wù)的完整名稱。

不光這樣,還可以用 gradle compTest或者even gradle cT來執(zhí)行compileTest任務(wù)。

指定執(zhí)行的腳本文件

subdir/myproject.gradle:

task hello {
    doLast {
        println "using build file '$buildFile.name' in '$buildFile.parentFile.name'."
    }
}

可以在上級目錄中這樣來執(zhí)行這個腳本文件:

gradle -q -b subdir/myproject.gradle hello

這里的-q是說只打印錯誤日志,其他信息類日志不打印

-b是指定目錄,用-p還可以指定項目名稱:

 gradle -q -p subdir hello

忽略UP-TO-DATE檢查

> gradle --rerun-tasks doIt
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容