11 - example with custom task class definition

This commit is contained in:
Juraj Michalek
2014-05-09 18:21:40 +02:00
parent d990899a5c
commit e3e264d8c2
2 changed files with 34 additions and 0 deletions

View File

@@ -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:"
}

View File

@@ -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