[native]: How to create dependencies between model-space tasks in different build scripts


(Hoobajoob) #1

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
        }
    }
}

(Hoobajoob) #2

Never mind! Found that the task I was trying to set .dependsOn for had not been given a task type. As if, for example, the someOtherComponentTask definition above had been declared like so:

    tasks {
        someOtherComponentTask {
        }
    }