How to print task name in gradle?

I have a question about gradle. I am new to this assembly and want to know how to print the name of the task or save it in a variable.

Something like that:

> gradle someTask someTask 

I think the code is like this

 task someTask { print ($arg[0]) } 

but this is not so.

Thanks!

+7
groovy gradle
source share
2 answers

Not sure if you need it, but you can get the names of the tasks that were used when calling Gradle by accessing the project.gradle object.

i.e.: given the following build.gradle

 task someTask << { println project.gradle.startParameter.taskNames } 

Then runs:

 gradle someTask someTask 

Gives output:

 :someTask [someTask, someTask] BUILD SUCCESSFUL Total time: 4.34 secs 
+15
source share

AFAIU, you need this:

 task someTask << { println ${name} } 
0
source share

All Articles