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'
    }
}

执行任务:

gradle dist

排除某个任务

gradle dist -x test

用简写的任务名称

gradle di

只要以“di”开头的任务只有一个,就可以这样执行,不一定非得是任务的完整名称。

不光这样,还可以用 gradle compTest或者even gradle cT来执行compileTest任务。

指定执行的脚本文件

subdir/myproject.gradle:

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

可以在上级目录中这样来执行这个脚本文件:

gradle -q -b subdir/myproject.gradle hello

这里的-q是说只打印错误日志,其他信息类日志不打印

-b是指定目录,用-p还可以指定项目名称:

 gradle -q -p subdir hello

忽略UP-TO-DATE检查

> gradle --rerun-tasks doIt

你可能感兴趣的:(Gradle极简笔记(一))