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

最新文章

  1. iOS 4s-6Plus屏幕自动适配及颜色转换为十六进制
  2. 解决报错 ora-00704 ora-00604 ora-00942 启动不了数据库问题
  3. iOS开发——高级篇——iOS中如何选择delegate、通知、KVO(以及三者的区别)
  4. Hadoop入门学习笔记---part1
  5. Oracle 全文索引相关命令
  6. IIS Web服务器支持高并发设置
  7. [Mapreduce]eclipse下写wordcount
  8. Maven学习(2) - Maven构建多模块Java工程
  9. J2EE 读取文件路径
  10. Java基金会——JUnit
  11. 006-接收键盘的输入(read)
  12. Linux安装mysql 在/etc下没有my.cnf 解决办法
  13. POJ 2125 Destroying The Graph [最小割 打印方案]
  14. Markdown介绍
  15. Django之事务
  16. Access导出excel
  17. nginx自动启动脚本
  18. ZAB协议和Paxos算法
  19. urllib2 调用salt restapi
  20. openLDAP 2

热门文章

  1. Tomcat Post请求大小限制
  2. browserslist 目标浏览器配置表
  3. 模块与包&amp;常用模块
  4. JavaScript 二维数组排列组合
  5. sass语法一(变量篇)
  6. [转载]hive中order by,sort by, distribute by, cluster by作用以及用法
  7. 【ArcGIS】最近遇到的几个已经被解决的问题
  8. Anaconda 执行命令报ssl错误
  9. Android之自定义View以及画一个时钟
  10. java操作svn【svnkit】实操