Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete task always UP-TO-DATE

Tags:

gradle

build

I've a simple task in Gradle:

task cleanBuild(type: Delete) {
    def build = ".src/buildfiles"
    FileTree tree = fileTree (dir: dbEditorBuild);
    tree.each { File file ->
        println file
    }
}

When I run it, I get this output:

:user:cleanBuild UP-TO-DATE
BUILD SUCCESSFUL

Total time: 1.656 secs

I've read the docs and it says that tasks results are cached for performance. I wanted to rerun the task, but I couldn't. And that was despite editing the task code. So, apparently, it seems that Gradle is not able to detect that the task has been changed, which kind of suck.

I've tried what others recommended, like adding this line to the task:

outputs.upToDateWhen { false }

But it doesn't have any effect.

like image 770
Ammaro Avatar asked Mar 08 '23 02:03

Ammaro


1 Answers

You define a task of the type Delete, but you don't define any files to delete. That is the reason, why your task is always up-to-date, since it has nothing to do. You can define which files will be deleted via the delete method. Everything you pass to this method will be evaluated via Project.files(...):

task myDelete(type: Delete) {
    delete 'path/to/file', 'path/to/other/file'
}

Please note, that your code example does not interfere with the up-to-date checks, it doesn't even interfere with the task at all. Since you are not using a doFirst/doLast closure, you are using the configuration closure of the task, which is executed during configuration phase. Since you are also not using any task methods, your code would mean absolutely the same if it would be placed outside of the task configuration closure.

As a small addition: Even if this specific problem is not caused by the Gradle up-to-date checks, there is a way to force Gradle to execute all tasks ignoring any task optimization: Simply add --rerun-tasks as command line argument, as described in the docs.

like image 135
Lukas Körfer Avatar answered Mar 10 '23 15:03

Lukas Körfer