# Task to build all projects

**URL:** <https://discuss.gradle.org/t/task-to-build-all-projects/18907>\
**Category:** Help/Discuss\
**Created:** [August 11, 2016, 4:55pm UTC](https://discuss.gradle.org/t/task-to-build-all-projects/18907 "2016-08-11T16:55:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsvoronin](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/dsvoronin/32/4236_2.png) [@dsvoronin](https://discuss.gradle.org/u/dsvoronin)\
**Post date:** [August 11, 2016, 4:55pm UTC](https://discuss.gradle.org/t/task-to-build-all-projects/18907/1 "2016-08-11T16:55:55Z")

</div>

I have multiproject build with android/java modules  
**Goal** : to have pretty and configurable one liner for CI, like

```gradle
./gradlew ciBuild

```

in root build.gradle i create following:

```gradle
task ciBuild {
      dependsOn subprojects.build
}

```

Ok, but not working! Because modules obtain `build` task only after plugin applied, so i wrap it into:

```gradle
gradle.projectsEvaluated {
    task ciBuild {
        dependsOn subprojects.build
    }
}

```

So far so good, but it won’t work if i want to enable `configure on demand` option, this callback just never invoked.  
Why i want `configure on demand`? because i’m working on decoupling my modules and want to have this room for optimization in future.

Are there any alternatives, or this whole idea is just wrong?

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [August 11, 2016, 7:15pm UTC](https://discuss.gradle.org/t/task-to-build-all-projects/18907/2 "2016-08-11T19:15:37Z")

</div>

You really won’t get any benefit from configure on demand here since you’ll have to configure every project anyhow. You’re basically saying “run task X for every subproject”. Well, to do that, we have to evaluate every subproject, thus negating any benefit from configure on demand. Configure on demand will only benefit you when doing partial builds, for example `./gradlew :someSubProject:build`.

Additionally, if you want to run the `build` task for every project, you can just run `./gradlew build`. There is no need to define a special task in the root project.

---

<div class="post-metadata">

**Author:** ![dsvoronin](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/dsvoronin/32/4236_2.png) [@dsvoronin](https://discuss.gradle.org/u/dsvoronin)\
**Post date:** [August 12, 2016, 8:29am UTC](https://discuss.gradle.org/t/task-to-build-all-projects/18907/3 "2016-08-12T08:29:56Z")

</div>

I will get benefit of `configure on demand` on dev machine, where i need to run only `:oneofmyapps:assemble` at a time. And of course i can’t use it on CI environment.

So if i want to add more checks on CI build, i just add `build.dependsOn myNewCheck` ?

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [August 12, 2016, 2:31pm UTC](https://discuss.gradle.org/t/task-to-build-all-projects/18907/4 "2016-08-12T14:31:47Z")

</div>

> [@dsvoronin](#):
>
> So if i want to add more checks on CI build, i just add build.dependsOn myNewCheck ?

The more idiomatic thing to do would be `check.dependsOn myNewCheck`. The result when running `build` would be the same since `build` depends on `check`.
