From e3e264d8c295cff8646e312c3d7e4bc6a5367572 Mon Sep 17 00:00:00 2001 From: Juraj Michalek Date: Fri, 9 May 2014 18:21:40 +0200 Subject: [PATCH] 11 - example with custom task class definition --- 11-task-class/build.gradle | 22 ++++++++++++++++++++++ README.md | 12 ++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 11-task-class/build.gradle diff --git a/11-task-class/build.gradle b/11-task-class/build.gradle new file mode 100644 index 0000000..dd99084 --- /dev/null +++ b/11-task-class/build.gradle @@ -0,0 +1,22 @@ + +// Definition of custom task class +class DateTask extends DefaultTask { + + String prefixText = "Today is:" + + @TaskAction + void printDate() { + def dateTime = new Date() + println "${prefixText} ${dateTime.dateString}" + } +} + +task today(type: DateTask) { + description "Display date" +} + +task verboseToday(type: DateTask) { + description "Display polite message and date" + prefixText "I would like to inform you that today is:" +} + diff --git a/README.md b/README.md index b782089..49f21b7 100644 --- a/README.md +++ b/README.md @@ -108,3 +108,15 @@ building decorators. gradle tasks gradle helloWorld + +## 11-task-class + +Gradle allows to define custom task class. This class should contain +one method with annotation @TaskAction. This method will be executed. +Each property defined on class level is configurable from gradle task +(see verboseToday). + + gradle tasks + gradle today + gradle verboseToday +