Force task execution in Gradle

build.gradle, gradle

Solution

Tasks have to be configured in the configuration phase. However, you are configuring it in a task action (`<< { ... }`), which runs in the execution phase. Because you are configuring the task too late, Gradle determines that it has nothing to do and prints `UP-TO-DATE`.

Below is a correct solution. Again, I recommend to use `doLast` instead of `<<` because it leads to a more regular syntax and is less likely added/omitted accidentally.

task backupFile(type: Copy) {
    from file(adjusting_file.replaceAll("\"", "")) 
    into file(backupDestinationDirectory + "/main/")
    doLast {
        println "[INFO] Main file backed up"
    }
}    

Problem

A certain amount of Gradle tasks I wrote, don't need any in- or output. Because of that, these tasks always get the status `UP-TO-DATE` when I call them. An example: ``` task backupFile(type: Copy) << { //Both parameters are read from the gradle.properties file from file(adjusting_file.replaceAll("\"", "")) into file(backupDestinationDirectory + "/main/") println "[INFO] Main file backed up" } ``` Which results in the following output: ``` :gradle backupFile :backupFile UP-TO-DATE ``` Is there a way to force a(ny) task to execute, regardless of anything? If there is, is it also possible to toggle task execution (e.g. telling the build script which tasks to run and which tasks to ignore)? I can't omit the `<<` tags, as that would make the tasks to always execute, which isn't what I desire. Many thanks in advance for your input.

Original source