Dependency on a group of tasks by the name of the group


(Attila Kelemen) #1

I wish if it were possible to add a task to a group (or to multiple groups) and then I could declare in the script that this group depends on a certain task or a group or a task depends on this group. It would be benefical in situations like this: When releasing there are numerous tasks doing modifications and there are certain conditions which must be met before releasing. It would be nice if checking those conditions would be easy to do before actually doing anything doing adjustment needed to be rollbacked on failure. So in this case the tasks executed when releasing could be put into a group like “release-write”. This way, I could declare “release-write” dependency for tasks checking if the conditions required for the release are met.

I imagine that when depending on a group, it does not execute all tasks of that group but if a task is otherwise executed and belongs to the group then executed before the task depending on the group.

For clarification: I don’t mean the groups currently in gradle which are for displaying tasks to the user grouped.


(Peter Niederwieser) #2

Thanks for the suggestion. Can you clarify what you mean by the following?

I imagine that when depending on a group, it does not execute all tasks of that group but if a task is otherwise executed and belongs to the group then executed before the task depending on the group.


(Attila Kelemen) #3

For example, build depends on test, so if I execute gradle build, it will also execute the test task. But assume that there are the following tasks: task1 in the group GroupOfTask1 and task2 in the group GroupOfTask2. If task2 depends on GroupOfTask1 and I execute gradle task2 then task1 is not executed. If however, there is a task task3 depending on both task1 and task2 and I execute gradle task3 then task1 must be executed before task2.

Perhaps naming the dependency between a group and something shouldn’t be named dependency, so noone might assume that it works the same way as dependency between tasks.


(Luke Daley) #4

You can add a dependency on all tasks of a certain group with:

someTask.dependsOn(tasks.matching { it.group = “someGroup” })


(Attila Kelemen) #5

This is not exactly what I want because this forces the execution of all tasks in the certain group. In my above previous comment, “gradle task2” would execute “task1”. Even though what you proposed helps in the release example of my post unless you want to release only certain subprojects.