Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle - Check which task is being executed

In my gradle file I want to know which task triggered the code block. e.g. If I run

gradle assembleVanillaDebug

from the terminal, I want to know in my gradle file that assembleVanillaDebug task is being executed. This will also help me in figuring out I am running debug build type task or release build type task. Can we know which task is being executed?

like image 301
Rajkiran Avatar asked Dec 13 '16 10:12

Rajkiran


People also ask

How do I view tasks in Gradle?

To see which tasks are available for our build we can run Gradle with the command-line option -t or --tasks. Gradle outputs the available tasks from our build script. By default only the tasks which are dependencies on other tasks are shown. To see all tasks we must add the command-line option --all.

Which are the tasks are performed by Gradle?

The work that Gradle can do on a project is defined by one or more tasks. A task represents some atomic piece of work which a build performs. This might be compiling some classes, creating a JAR, generating Javadoc, or publishing some archives to a repository.

How do I list all tasks in Gradle?

To get an overview of all Gradle tasks in our project, we need to run the tasks task. Since Gradle 5.1, we can use the --group option followed by a group name. Gradle will then show all tasks belonging to the group and not the other tasks in the project.

What is afterEvaluate in Gradle?

> gradle -q test Adding test task to project ':project-a' Running tests for project ':project-a' This example uses method Project. afterEvaluate() to add a closure which is executed after the project is evaluated. It is also possible to receive notifications when any project is evaluated.


1 Answers

In the end,

gradle.startParameter.taskNames

proved to be my friend. gradle.startParameter.getTaskNames() would return you the list of all tasks being executed in current build.

e.g. For gradle clean assembleVanillaDebug, it will return you a list of tasks clean and assembleVanillaDebug.

like image 196
Rajkiran Avatar answered Sep 17 '22 23:09

Rajkiran