Gradle: how to split a task into sequentially executed actions

Is it possible to set tasks in gradle, for example

task foo(dependsOn: jar){ // task 1 // task 2 // task 3 . . . // task n } 

where is the execution order jar > foo > task 1 > task 2 > task 3 > ...> task n ? I do not want nested tasks (i.e. task 1 , task 2 , etc.) to be displayed to the user. I want the foo task to display.

+4
source share
2 answers

There is no way in Gradle to display only selected tasks (in the strict sense). However, there is a way to show only selected tasks in gradle tasks . If the --all flag is not used, gradle tasks will show only the "root" tasks (that is, tasks that no other task depends on) and tasks that have their own set of group properties.

+3
source

It looks like you can just do the following:

 task foo(dependsOn: ['clean', 'jar']){ foo << { println "First" } foo << { println "Second" } foo << { println "Third" } . . . } 

where << is short for doLast . I think this is very important, since only foo shown. Nested tasks remain hidden from the end user. And if you execute foo , you will get

 First Second Third 
+3
source

Source: https://habr.com/ru/post/1433844/


All Articles