# One task to build everything

**URL:** <https://discuss.gradle.org/t/one-task-to-build-everything/6987>\
**Category:** Old Forum Archive\
**Created:** [February 6, 2012, 6:43pm UTC](https://discuss.gradle.org/t/one-task-to-build-everything/6987 "2012-02-06T18:43:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gward](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gward/32/854_2.png) [@gward](https://discuss.gradle.org/u/gward)\
**Post date:** [February 6, 2012, 6:43pm UTC](https://discuss.gradle.org/t/one-task-to-build-everything/6987/1 "2012-02-06T18:43:00Z")

</div>

An ancient tradition with Make is to make your first target depend on everything, so simply running “make” builds everything. SCons does this even better: running “scons” means “build all targets under the current directory”. Works great, and you don’t need to follow ancient traditions; it _just works_.

Is there an equivalent with Gradle – e.g. a “build everything” task? Or would I have to define it myself and make it depend on everything?

Thanks –

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [February 6, 2012, 7:00pm UTC](https://discuss.gradle.org/t/one-task-to-build-everything/6987/2 "2012-02-06T19:00:00Z")

</div>

The conventional task for just creating everything that the build creates in Gradle is the ‘assemble’ task. For creating and testing, it’s ‘build’.

The ‘assemble’ task builds all of the publish artifacts that are part of the ‘archives’ configuration which is the default configuration for publications. The ‘build’ task _depends on_ ‘assemble’ and ‘check’ (which runs tests/verifications).

So how to achieve this depends on what kind of build you have and what it creates.

---

<div class="post-metadata">

**Author:** ![gward](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gward/32/854_2.png) [@gward](https://discuss.gradle.org/u/gward)\
**Post date:** [February 6, 2012, 7:11pm UTC](https://discuss.gradle.org/t/one-task-to-build-everything/6987/3 "2012-02-06T19:11:00Z")

</div>

Nope: “gradle assemble” reports that it has nothing to do. Example:

```gradle
$ hg purge --all
$ gradle assemble
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
  BUILD SUCCESSFUL
  Total time: 3.289 secs

```

If you’re not familiar with Mercurial, “hg purge --all” means “remove all files not tracked by Mercurial” – i.e. return my working directory to a pristine state, as though it were a fresh checkout. This guarantees there are no build products, or caches/databases maintained by build tools.

So it’s impossible that all my tasks are up-to-date.

I wonder if this is because I’m using sourceSets to specify various Java components; I simply don’t have a “main” component. Thus, “compileJava” and downstream tasks have nothing to do… but “compileCommonJava” and “compileCoredbJava” (two of my source sets) certainly have stuff to do.

Here’s a skeleton of my build.gradle:

```gradle
apply plugin: 'java'
sourceSets {
      // Common libraries that would be useful for anyone writing Java
    // anywhere
    common {
        output.classesDir = file('.build/classes/common')
        java {
            srcDirs = [...],
            compileClasspath = files([...])
        }
    policy {
        output.classesDir = file('.build/classes/policy')
        java {
            srcDirs = [...]
        }
        compileClasspath = files([...])
    }
    [...other components...]
}

```

As a temporary hack, I’ve added an “all” target that forces compiling all my source sets:

```gradle
task all {
    dependsOn commonClasses, policyClasses, coredbClasses
}

```

But surely there is a better way…?

---

<div class="post-metadata">

**Author:** ![gward](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gward/32/854_2.png) [@gward](https://discuss.gradle.org/u/gward)\
**Post date:** [February 6, 2012, 7:15pm UTC](https://discuss.gradle.org/t/one-task-to-build-everything/6987/4 "2012-02-06T19:15:00Z")

</div>

Oh yeah: aren’t tasks “assemble” and “build” added by the Java plugin? What if I’m using Gradle for a non-Java project? (Hypothetical example: I _am_ building a Java project, but I’m curious.)

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [February 6, 2012, 7:19pm UTC](https://discuss.gradle.org/t/one-task-to-build-everything/6987/5 "2012-02-06T19:19:00Z")

</div>

Do you end up creating jars of these source sets?

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [February 6, 2012, 7:20pm UTC](https://discuss.gradle.org/t/one-task-to-build-everything/6987/6 "2012-02-06T19:20:00Z")

</div>

Then you’d use the ‘build«configuration»’ task rule as the start, and add your own ‘build’ task that did this likely by depending on one ore more ‘build«confguration»’ tasks.

---

<div class="post-metadata">

**Author:** ![gward](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gward/32/854_2.png) [@gward](https://discuss.gradle.org/u/gward)\
**Post date:** [February 6, 2012, 7:32pm UTC](https://discuss.gradle.org/t/one-task-to-build-everything/6987/7 "2012-02-06T19:32:00Z")

</div>

Currently: no, I haven’t bothered. Don’t really need jars, since I just need to ensure that the classes from component i-1 are in the compile-time classpath of component i. A classes/$name directory is just as good for that purpose as $name.jar.

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [February 6, 2012, 7:35pm UTC](https://discuss.gradle.org/t/one-task-to-build-everything/6987/8 "2012-02-06T19:35:00Z")

</div>

right, that’s the missing piece. You could just wire this in to build:

```gradle
build {
  dependsOn { sourceSets*.output }
}

```
