In Gradle we can group related tasks using the group property of a task. We provide the name of our group and if we look at the output of the tasks task we can see our tasks grouped in section with the given name. In the next sample we create a new task publish and assign it the group name Publishing.

0.task publish(type: Copy) {
1.from "sources"
2.into "output"
3.}
4. 
5.configure(publish) {   
6.group = 'Publishing'
7.description = 'Publish source code to output directory'
8.}

If we execute tasks we get the following output:

$ gradle tasks
:tasks
 
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
 
Help tasks
----------
dependencies - Displays the dependencies of root project 'taskGroup'.
help - Displays a help message
projects - Displays the sub-projects of root project 'taskGroup'.
properties - Displays the properties of root project 'taskGroup'.
tasks - Displays the tasks runnable from root project 'taskGroup' (some of the displayed tasks may belong to subprojects).
 
Publishing tasks
----------------
publish - Publish source code to output directory
 
To see all tasks and more detail, run with --all.
 
BUILD SUCCESSFUL
 
Total time: 2.327 secs

Suppose we apply the Java plugin to our project. We get a lot of new tasks, which are already in groups with names like Build and Documentation. If we want to add our own custom tasks to one of those groups we only have to use the correct name for the group property of our task. In the following build file we apply the Java plugin and use the Build group name as a group name for our task. The name is defined as a constant of the BasePlugin.

00.apply plugin: 'java'
01. 
02.task publish(type: Copy) {
03.from 'sources'
04.into 'output'
05.}
06. 
07.configure(publish) {   
08.group = BasePlugin.BUILD_GROUP // Or use 'build'
09.description = 'Publish source code to output directory'
10.}

When we run tasks again we can see our task is in the Build section together with the tasks added by the Java plugin:

$ gradle tasks
:tasks
 
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
 
Build tasks
-----------
assemble - Assembles all Jar, War, Zip, and Tar archives.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles the main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
publish - Publish source code to output directory
testClasses - Assembles the test classes.
 
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
 
Help tasks
----------
dependencies - Displays the dependencies of root project 'taskGroup'.
help - Displays a help message
projects - Displays the sub-projects of root project 'taskGroup'.
properties - Displays the properties of root project 'taskGroup'.
tasks - Displays the tasks runnable from root project 'taskGroup' (some of the displayed tasks may belong to subprojects).
 
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
 
Rules
-----
Pattern: build<configurationname>: Assembles the artifacts of a configuration.
Pattern: upload<configurationname>: Assembles and uploads the artifacts belonging to a configuration.
Pattern: clean<taskname>: Cleans the output files of a task.
 
To see all tasks and more detail, run with --all.
 
BUILD SUCCESSFUL
 
Total time: 2.896 secs

Gradle Goodness: Adding Tasks to a Predefined Group的更多相关文章

  1. Gradle Goodness: Excluding Tasks for Execution

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

  2. 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 ...

  3. 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. ...

  4. Gradle Goodness: Display Available Tasks

    To see which tasks are available for our build we can run Gradle with the command-line option -t or ...

  5. Gradle Goodness: Task Output Annotations Create Directory Automatically

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

  6. org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection

    转载请注明出处:http://www.cnblogs.com/cnwutianhao/p/6709758.html Android Studio导入项目报错: org.gradle.api.inter ...

  7. Android studio Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to

    http://blog.csdn.net/FlyRabbit_1/article/details/74536317 Error:org.gradle.api.internal.tasks.Defaul ...

  8. Gradle Goodness: Copy Files with Filtering

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

  9. 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 ...

随机推荐

  1. Filter的常见应用

    1.字符编码过滤器 实现功能,在a.jsp中填写用户名提交到b.jsp,在b.jsp中读取参数名. a.jsp <body> <form action="encoding/ ...

  2. eclipse中php项目开发的环境配置说明

    PHP开发的环境配置比Java开发要简单点,也就是我们不用安装jdk了,我们不用安装tomcat了,仅仅通过一种集成环境来安装就好了. PHP开发,其实有很多种环境配置方式,我这里使用了XAMPP进行 ...

  3. C10K问题摘要

    本文的内容是下面几篇文章阅读后的内容摘要: http://www.kegel.com/c10k.html (英文版) http://www.oschina.net/translate/c10k (中文 ...

  4. JS如何使用Math.atan2获取两点之间角度的实践案例

    本文主要介绍使用如何实现手动拖拽旋转元素的效果. 1.简述 最近在研究如何实现手动控制元素的旋转效果,在网上找了很多,都没有找出类似的实现,因此经过一些调研和计算,最终完美实现效果,在这里记录下来. ...

  5. c# json数组动态字段名

    根据给定的列名动态生成json数组 List<string> cols = new List<string>() { "姓名","性别" ...

  6. Java数字和字符串的相互转换(BigDecimal的使用)

    String s = "100."; double d1 = "1.23"; double d = Double.parseDouble(s); s = Str ...

  7. windows c++ 修改用户的文件夹操作权限

    一般Windows下的系统文件(夹)只让受限帐户读取而不让写入和修改.如果要开启写操作权限就需要手动修改文件(夹)的用户帐户安全权限(这操作当然要在管理员帐户下执行).以下用程序封装了一下该操作: # ...

  8. mybatis ${}使用注意事项

    ${key}有值, ${key,jdbcType=VARCHAR}没有值 总结:${}使用时不要指定jdbcType等属性,指定这些反而取不到值,这也是跟#{}的一个区别.以上只是开发中遇到的情况,具 ...

  9. Java不带.classpath的svn项目下载,转成到eclipse中

    .classpath是Eclipse的工程文件,别人没有将工程的信息传到SVN库中,就检查不出.classpath文件,识别不了项目结构. 这种做法也是比较提倡的方法.SVN上只要有项目的源码信息就可 ...

  10. 【Leetcode】【Medium】Linked List Cycle II

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. 解题: ...