Is there a way where I can get the details of the current task being executed? For example I want to print the name of the current task being executed, etc.
I tried this :
task printMyNameIfYouCan << {
println $task.name
}
But it fails with
Execution failed for task ':printMyNameIfYouCan'.
> Could not find property '$task' on task ':printMyNameIfYouCan'.
NOTE: I checked How to print task name in gradle?, but this is not I'm looking at.
You can also access the task's path by using the tasks. For this, you can call the getByPath() method with a task name, or a relative path, or an absolute path. Copy and save the below given code into build. gradle file.
In Gradle, Task is a single unit of work that a build performs. These tasks can be compiling classes, creating a JAR, Generating Javadoc, and publishing some archives to a repository and more. It can be considered as a single atomic piece of work for a build process.
Right-click on the Eclipse project, choose Configure -> Add Gradle Nature.
gradle.taskGraph.afterTask {
Task task,TaskState state ->
if (state.failure) { println "$task.name FAILED"}
else { println "$task.name SUCCESSFULL"}
}
task printMyNameIfYouCan {
doLast {
println name
}
}
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