class HelloTask extends DefaultTask { @Internal String msg = "default name" @Internal int age = 20 @TaskAction void sayHello() { println("hello ${msg}, age is ${age}") } @Override int compareTo(Task o) { return super.compareTo(o) } } task hello(type: HelloTask) task task1 { println("configure task1") doLast { println("task 1") } } task task2 { doLast { println("task 2") } } hello.configure { msg = "ok" age=21 } hello.dependsOn(task1) hello.finalizedBy(task2) tasks.whenTaskAdded { theTask -> if (theTask.name.equals("assembleC110000Debug")) { theTask.dependsOn(hello) } }
--------------------------------------
输出如下
Executing tasks: [:app:assembleC110000Debug] in project D:\work\zhida_project\newsvn\Zhida_Schedule\branches\newUI
> Configure project :app
configure task1
> Task :app:createC110000DebugVariantModel UP-TO-DATE
> Task :app:task1
task 1
> Task :app:hello
hello ok, age is 21
> Task :app:task2
task 2