I have the following code which works fine:
allprojects {
tasks.whenTaskAdded { task ->
if (task.name =~ /generate.*Proto/) { // ①
task.dependsOn(protolockStatus)
task.finalizedBy(protolockCommit)
}
}
}
Rather than assuming some task naming convention on the line commented with ①, I'd like to make the condition based on the type of the task. I had thought type instanceof
would work, but it did not. I also don't see any methods that would provide the type of the task. Is there a way to do this?
You could use the class
of the task for that. So for example, you could try this:
allprojects {
tasks.whenTaskAdded { task ->
println "Type is " + task.class.simpleName
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With