I am building a project and have the following issue: I have two subprojects which are very similar, they share all the same tasks task1, task2, task3; only one task is a little different, taskDiff. They both have the task, and it does very similar things, but is a little different in both subprojects
My idea was to create a group which contains both subprojects, and task1, task2, task3 are defined in that group. That way, both subprojects can be called with those tasks.
The problem is, taskDiff needs to be defined in the subprojects. But the tasks of the group depend on that task. When I do a
task1.dependsOn taskDiff
I get an error of course, because gradle doesn’t know taskDiff at that level.
Can you give me some hint on how to proceed here?
I hope I could make myself clear here, I am quite new to gradle.
I solved it in the meantime already, because I realized how this inheritance actually works.
configure(dockerProjects){
task task1 {
...
}
task taskDiff {
// some things that should always be done in this task
}
}
and then
configure(project(’:my-docker-subproject’)) {
task otherTask {
...
}
taskDiff {
//here I am extending the inherited task, e.g. with doFirst{}
}
task1.dependsOn taskDiff
}
So I could extend taskDiff in the subproject (note, that you can’t write ‘task taskDiff {}’ but have to write ‘taskDiff{}’ and then with things like ‘doFirst’ you can combine the inherited taskSteps with the new ones.