# Invoking master's build task from a subproject

**URL:** <https://discuss.gradle.org/t/invoking-masters-build-task-from-a-subproject/21456>\
**Category:** Help/Discuss\
**Created:** [February 3, 2017, 10:06am UTC](https://discuss.gradle.org/t/invoking-masters-build-task-from-a-subproject/21456 "2017-02-03T10:06:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Fisher](https://avatars.discourse-cdn.com/v4/letter/m/cc9497/32.png) [@Mark\_Fisher](https://discuss.gradle.org/u/Mark_Fisher)\
**Post date:** [February 3, 2017, 10:06am UTC](https://discuss.gradle.org/t/invoking-masters-build-task-from-a-subproject/21456/1 "2017-02-03T10:06:21Z")

</div>

I have a multiproject build where I want to refer from a subproject to a master task, which will then invoke the task on all subprojects.

The subproject build script has something like:

```
task compileAll {
  dependsOn ':build'
}

mySubProjectTask {
  dependsOn compileAll
}

```

but this doesn’t work. It runs ‘:buildscript’ in master instead of the equivalent of ‘cd master; ./gradlew build’

How do I refer to the same task in the master project that would invoke the ‘build’ task on all subprojects in this way, as if I was in master?

It’s easy to refer to another subproject’s task, with ‘:SubProject:taskName’, but I can’t do ‘:build’ or ‘::build’, both run the wrong task.

Thanks.

---

<div class="post-metadata">

**Author:** ![Mark\_Fisher](https://avatars.discourse-cdn.com/v4/letter/m/cc9497/32.png) [@Mark\_Fisher](https://discuss.gradle.org/u/Mark_Fisher)\
**Post date:** [February 3, 2017, 10:25am UTC](https://discuss.gradle.org/t/invoking-masters-build-task-from-a-subproject/21456/2 "2017-02-03T10:25:54Z")

</div>

This almost works, but the project dependency order doesn’t work correctly:

```
task compileAll {
  project.rootProject.subprojects.each { p ->
    if (p.tasks.findByPath('build')) {
      dependsOn p.tasks.findByPath('build')
    }
  }
}

```

i.e. if project A dependsOn B, using this method doesn’t run `:B:build` before `:A:Build`
