美文网首页
Gradle Task编写

Gradle Task编写

作者: mc_luo | 来源:发表于2017-09-14 14:43 被阅读0次

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'
    }
}
  1. 执行task
>gradle compile
:compile
compiling source
  1. 执行多个task
>gradle dist test
:compile
compiling source
:compileTest
compiling unit tests
:test
running unit tests
:dist
building the distribution

每个task只会执行一次,所以 gradle test test 执行效果和 gradle test一样

  1. 移除tasks
>gradle dist -x test
:compile
compiling source
:dist
building the distribution
  1. 选择执行脚本
    subdir/myproject.gradle
task hello {
    doLast {
        println "using build file '$buildFile.name' in '$buildFile.parentFile.name'."
    }
}

执行

> gradle -q -b subdir/myproject.gradle hello
using build file 'build.gradle' in 'subdir'.
  1. 选择执行目录
> gradle -q -p subdir hello
using build file 'build.gradle' in 'subdir'.

6.生成profile文件

>gradle test --profile

相关文章

网友评论

      本文标题:Gradle Task编写

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