Reputation: 655
We're building an archetype pattern using cookiecutter. This essentially means we have a nested structure with an outer build.gradle
and an inner build.gradle
. Is there a way make the tasks from the inner build.gradle
available as tasks on the outer project?
I'm thinking of using a GradleBuild
task in the outer build.gradle
to invoke the inner tasks but I'm not certain how to parse and load all the tasks from the inner build.gradle
within the outer one. What I was thinking was just catching the <task> not found
error on the outer build.gradle
and then trying to run that task on the inner build.gradle
. Does anyone know how to catch the <task> not found
exceptions and run some arbitrary task at that point?
Upvotes: 0
Views: 81
Reputation: 14493
Did you consider using composite builds?
However, it is not necessary to catch that error as you can simply define a task rule that will create any missing task on the run. Simply register a rule like the one below:
tasks.addRule("Pattern: <task>") { name ->
task(name, type: GradleBuild) {
dir = // apply your setup here
tasks = [name]
}
}
Upvotes: 1