美文网首页
使用gradle命令执行

使用gradle命令执行

作者: 浔它芉咟渡 | 来源:发表于2017-07-03 21:59 被阅读118次

    执行多个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指令已经被排除了,并没有执行。

    相关文章

      网友评论

          本文标题:使用gradle命令执行

          本文链接:https://www.haomeiwen.com/subject/svgzcxtx.html