Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print the current task name in gradle

Tags:

gradle

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.

like image 452
Sundeep Gupta Avatar asked May 27 '14 05:05

Sundeep Gupta


People also ask

How do I find the task name in Gradle?

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.

What is in Gradle task?

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.

How do I view Gradle tasks in Eclipse?

Right-click on the Eclipse project, choose Configure -> Add Gradle Nature.


2 Answers

gradle.taskGraph.afterTask {
    Task task,TaskState state ->
        if (state.failure) {    println "$task.name FAILED"}
        else               {    println "$task.name SUCCESSFULL"}
}
like image 88
gilles Avatar answered Sep 23 '22 23:09

gilles


task printMyNameIfYouCan {
    doLast {
        println name
    }
}
like image 33
Peter Niederwieser Avatar answered Sep 25 '22 23:09

Peter Niederwieser