Gradle Task编写

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

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,828评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,118评论 6 342
  • 是什么? 在语法上是基于Groovy语言的(Groovy 是一种基于JVM的敏捷开发语言,可以简单的理解为强类型语...
    千山万水迷了鹿阅读 99,877评论 4 122
  • 前言 为什么需要学Gradle? Gradle 是 Android 现在主流的编译工具,虽然在Gradle 出现之...
    真笨笨鱼阅读 5,381评论 0 0
  • 秦诏版,亦称秦量诏版,青铜制。系秦始皇二十六年统一量衡之诏书,为存垂久远,将其刻在金属版上故名。其刻字风格大体近于...
    逸闲居主人阅读 2,707评论 0 0

友情链接更多精彩内容