To see which tasks are available for our build we can run Gradle with the command-line option -t or --tasks. Gradle outputs the available tasks from our build script. By default only the tasks which are dependencies on other tasks are shown. To see all tasks we must add the command-line option --all.

00.3.times { counter ->
01.task "lib$counter" {
02.description = "Build lib$counter"
03.if (counter > 0) {
04.dependsOn = ["lib${counter - 1}"]
05.}
06.}
07.}
08. 
09.task compile {
10.dependsOn {
11.project.tasks.findAll {
12.it.name.startsWith('lib')
13.}
14.}
15.description = "Compile sources"
16.}
$ gradle -q -t
 
------------------------------------------------------------
Root Project
------------------------------------------------------------
 
Tasks
-----
:compile - Compile sources
$ gradle -q --tasks -all
 
------------------------------------------------------------
Root Project
------------------------------------------------------------
 
Tasks
-----
:compile - Compile sources
:lib0 - Build lib0
:lib1 - Build lib1
:lib2 - Build lib2

But if we add our tasks to a group, we get even more verbose output. Gradle will group the tasks together and without the --all option we get to see all tasks belonging to the group, even those that are dependency tasks. And with the --all option we see for each task on which tasks it depends on. So by setting the group property on the task we get much better output when we ask Gradle about the available tasks.

00.3.times { counter ->
01.task "lib$counter" {
02.description = "Build lib$counter"
03.if (counter > 0) {
04.dependsOn = ["lib${counter - 1}"]
05.}
06.}
07.}
08. 
09.task compile {
10.dependsOn {
11.project.tasks.findAll {
12.it.name.startsWith('lib')
13.}
14.}
15.description = "Compile sources"
16.}
17. 
18.tasks*.group = 'Compile'
$ gradle -q -t
 
------------------------------------------------------------
Root Project
------------------------------------------------------------
 
Compile tasks
-------------
:compile - Compile sources
:lib0 - Build lib0
:lib1 - Build lib1
:lib2 - Build lib2
$ gradle -q --tasks -all
 
------------------------------------------------------------
Root Project
------------------------------------------------------------
 
Compile tasks
-------------
:compile - Compile sources [:lib0, :lib1, :lib2]
:lib0 - Build lib0
:lib1 - Build lib1 [:lib0]
:lib2 - Build lib2 [:lib1]

Gradle Goodness: Display Available Tasks的更多相关文章

  1. Gradle Goodness: Group Similar Tasks

    In Gradle we can assign a task to a group. Gradle uses the group for example in the output of $ grad ...

  2. Gradle Goodness: Automatic Clean Tasks

    Gradle adds the task rule clean<Taskname> to our projects when we apply the base plugin. This ...

  3. Gradle Goodness: Continue Build Even with Failed Tasks

    If we run a Gradle build and one of the tasks fails, the whole build stops immediately. So we have f ...

  4. Gradle Goodness: Task Output Annotations Create Directory Automatically

    Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...

  5. Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects

    Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects Gradle is very flexible. ...

  6. Gradle Goodness: Copy Files with Filtering

    Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...

  7. Gradle Goodness: Changing Name of Default Build File

    Gradle uses the name build.gradle as the default name for a build file. If we write our build code i ...

  8. Gradle Goodness: Excluding Tasks for Execution

    In Gradle we can create dependencies between tasks. But we can also exclude certain tasks from those ...

  9. Gradle Goodness: Adding Tasks to a Predefined Group

    In Gradle we can group related tasks using the group property of a task. We provide the name of our ...

随机推荐

  1. mybatis-generator 动态生成实体对象、dao 以及相关的xml映射文件

    .新建maven空项目 2.修改pom.xml文件 <?xml version="1.0" encoding="UTF-8"?> <proje ...

  2. javascript中函数的写法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Myeclipse中设置jsp页面的默认编码格式

    在MyEclispe中创建Jsp页面,Jsp页面的默认编码是“ISO-8859-1”,如下图所示: 在这种编码下编写中文是没有办法保存Jsp页面的,会出现如下的错误提示: 因此可以设置Jsp默认的编码 ...

  4. mysql备份整个数据库的表结构和数据

  5. CentOS网卡显示为__tmpxxxxxxxx

    一台服务器做了2组端口绑定(bonding),其中一组bond总是不成功,发现少了eth0/eth5 两个网卡,后来通过ifconfig -a 发现多了两个__tmpxxx的网卡 ifconfig - ...

  6. Flume -- Transfer one type of source to another type

    Source within Flume is a kind of Server for outside client. Sink within Flume is a kind of client fo ...

  7. JS中0与‘0’

    JS中0为false,字符串‘0’为true

  8. SQLServer数据库执行较大的脚本

    当我们需要在SQLServer数据库里面执行一个比较大的文件(比如2GB)时,会发现数据库根本无法打开该脚本文件,原因是因为查询分析器只能执行100M以内的文件,所以脚本过大就会造成内存溢出.下面是具 ...

  9. Hadoop配置文件详解

    1       获取默认配置 配置hadoop,主要是配置core-site.xml,hdfs-site.xml,mapred-site.xml三个配置文件,默认下来,这些配置文件都是空的,所以很难知 ...

  10. Java实例---俄罗斯方块

    代码分析 定义格子 package com.ftl.tetris; /** * 定义格子 */ import java.awt.image.BufferedImage; public class Ce ...