使用gradle命令执行

执行多个tasks

可以在命令中执行多个task任务,比如,可以执行

gradle complie test

这将会执行compile和test的任务。gradle不仅会执行他们自己的任务,还会执行所依赖的任务,每一个任务仅仅执行一次,不管他在在命令行中怎么特殊,或者作为一个依赖给其他的task。看一个列子

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 test

> gradle dist test
:compile
compiling source
:compileTest
compiling unit tests
:test
running unit tests
:dist
building the distribution

BUILD SUCCESSFUL

Total time: 1 secs

在上面定义的task中,dist和test都依赖了compile的task,执行命令后,compile的task只执行了一次。


image

排除task

可以使用 -x 命令来排除需要执行的task,

> gradle dist -x test
:compile
compiling source
:dist
building the distribution

BUILD SUCCESSFUL

Total time: 1 secs

从输出来看,test指令已经被排除了,并没有执行。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容