Force Gradle to run task even if it is UP-TO-DATE

If you want to rerun all tasks, you can use command line parameter --rerun-tasks. However this is basically the same as doing a clean as it reruns all the tasks.

If you want to run a single task every time, then you can specify that it is never up-to-date:

mytask {
    outputs.upToDateWhen { false }
}

If you want to rerun a single task once and leave all the other tasks, you have to implement a bit of logic:

mytask {

    outputs.upToDateWhen { 
        if (project.hasProperty('rerun')) {
            println "rerun!"
            return false
        } else {
            return true
        }
    }
}

And then you can force the task to be re-run by using:

gradle mytask -Prerun

Note that this will also re-run all the tasks that depend on mytask.