mirror of
https://github.com/ysoftdevs/gradle-training.git
synced 2026-01-11 14:30:40 +01:00
11 - example with custom task class definition
This commit is contained in:
22
11-task-class/build.gradle
Normal file
22
11-task-class/build.gradle
Normal 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:"
|
||||
}
|
||||
|
||||
12
README.md
12
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user