I have a project with a few different native components to build, and the build script was getting large enough that I wanted to break out the component config into their own build script files, using apply from:
to aggregate them into build.gradle
.
I have a few model-space tasks defined with each component, and in the main build.gradle
file, I’d like to create a dependsOn
relationship between one of the tasks in one component’s build script and a task in another component’s build script.
But, I can’t find a way, from within build.gradle
to refer to either of these tasks without getting an error like this:
* What went wrong:
A problem occurred configuring root project 'project-x'.
> Exception thrown while executing model rule: tasks { ... } @ build.gradle line 26, column 5
> Could not find property 'someComponentTask' on task ':tasks'.
Question: Given the basic build script structure shown below, how can I change build.gradle
so it correctly establishes a dependency between a model-space task defined in buildSomeComponent.gradle
and a different model-space task defined in buildSomeOtherComponent.gradle
?
build.gradle:
apply from: 'buildSomeComponent.gradle'
apply from: 'buildSomeOtherComponent.gradle'
model {
tasks {
someComponentTask.dependsOn someOtherComponentTask
}
}
buildSomeComponent.gradle:
model {
components {
// component config here
}
tasks {
someComponentTask(Exec) {
// exec something
}
}
}
buildSomeOtherComponent.gradle:
model {
components {
// component config here
}
tasks {
someOtherComponentTask(Exec) {
// exec something
}
}
}