Build is considered UP-TO-DATE even when no outputs are defined

I’m trying to construct a simple proof-of-concept gradle framework for a project. Whenever I try to execute a task multiple times in a row without editing the build.gradle, I get an UP-TO-DATE message, and the task is skipped. According to the documentation at http://www.gradle.org/docs/current/userguide/more_about_tasks.html#sec:up_to_date_checks: “A task with no defined outputs will never be considered up-to-date.”

Am I doing something wrong? How do I force gradle to always execute a task no matter what? Thanks in advance

build.gradle

version = "gradle_test_1.0.0"
  task dist(type: Zip) {
    classifier = project.version + "_bin"
    from System.getProperty("user.dir")
    include 'bin/*'
}

Command line used

gradle -b subdir/build.gradle dist

output of “gradle -v”:

  ------------------------------------------------------------  Gradle 1.12  ------------------------------------------------------------

Build time:

2014-04-29 09:24:31 UTC Build number: none Revision:

a831fa866d46cbee94e61a09af15f9dd95987421

Groovy:

1.8.6 Ant:

Apache Ant™ version 1.9.3 compiled on December 23 2013 Ivy:

2.2.0 JVM:

1.7.0_51 (Oracle Corporation 24.45-b08) OS:

Linux 3.11.0-19-generic amd64

Most built-in task types, such as ‘Zip’, already define their inputs and outputs. To force a particular task to rerun, you can clean that task with ‘gradle cleanTaskName taskName’ (requires at least ‘base’ plugin). Alternatively, you can force all tasks to rerun with ‘–rerun-tasks’. ‘gradle clean’ typically has a similar effect.

The --rerun-tasks flag appears to be doing exactly what I needed. Thanks!

It seems I spoke too early. For individual build.gradle files, the --rerun-tasks flag is working, but when I try to assemble multiple builds together, the UP-TO-DATE message is appearing.

I want to have a top-level build.gradle script that does some environment setup, calls into other gradle scripts’ build and dist tasks, and then bundles everything together.

top-level build.gradle

task setup_env(type: Exec) {
    //do stuff
}
  task build_project_1(type: GradleBuild) {
    buildFile = 'rel/p1.gradle'
    tasks = ['build', 'dist']
}
  task setup_db(type: Exec) {
    dependsOn build_project_1
    //do stuff
}
  task build_project_2(type: GradleBuild) {
    dependsOn build_project_1, setup_db
    buildFile = 'subdir/p2.gradle'
    tasks = ['build', 'dist']
}
  task build_project_n(type: GradleBuild) {
    dependsOn build_project_m, build_project_foo, setup_db
    buildFile = 'subdir/pn.gradle'
    tasks = ['build', 'dist']
}
  task build_sub_projects {
    dependsOn setup_db, build_project_1, build_project_2, ...
}
  task build_all {
    tasks.setup_env.execute()
    tasks.build_sub_projects.execute()
}

All the sub projects’ gradle scripts are the same for now:

version = "project_n_v1.0.0.0"
  import org.apache.tools.ant.taskdefs.condition.Os
  task build(type: Exec) {
    //call makefile, or whatever the project needs
}
  task dist(type: Zip) {
    classifier = project.version + "_bin"
    from System.getProperty("user.dir")
    include 'bin/**/*'
}

Call each individual sub-gradle file with --rerun-tasks will rerun the build and dist tasks just fine; UP-TO-DATE never occurs

gradle --rerun-tasks -b subdir/p1.gradle build dist

However, when attempting to run the top-level build.gradle file does result in UP-TO-DATE:

gradle --rerun-tasks build_all

I’ve tried to work around the problem by explicitly defining an output that doesnt exist in the build_all task. This doesn’t work.

task build_all {
    outputs.dir new File('no-exist')
    tasks.setup_env.execute()
    tasks.build_sub_projects.execute()
}

I’ve also tried to delete the .gradle cache in the working directory as well as in the home directory ~/.gradle/caches. this also doesn’t do anything; the UP-TO-DATE message continues to plague me. In the production environment, gradle will be invoked through jenkins, so a fresh workspace should exist every time; but for testing we are running things manually.

Calling the internal ‘task.execute()’ method is unsupported and will cause troubles. Settings such as ‘–rerun-tasks’ don’t propagate to ‘GradleBuild’ tasks. These are separate builds which need to be configured separately (via the task). In any case, these ‘GradleBuild’ tasks don’t seem right. You should probably have a single multi-project build instead (see the “multi-project builds” chapter in the Gradle User Guide).