How can a clean task define no outputs?

(binyan357) #1

I have the following defined for configuring the ‘clean’ task:

clean {
 ext.deployDir = 'foo/bar'
 ext.inputFiles = fileTree(dir: deployDir, include: 'rest-example-*.war')
 inputs.files inputFiles
    doLast {
  delete inputFiles

My task runs every time when I execute “gradle clean” and in the debug output I see

14:34:58.908 [INFO] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Executing task ‘:rest-example:clean’ (up-to-date check took 0.0 secs) due to:

Task has not declared any outputs. 14:34:58.908 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ‘:rest-example:clean’.

So, the 2 issues I see are 1.) it never executes the delete since the wars are still there and 2.) how do you specify outputs for a case like this.

BTW, I didn’t use “outputs.dir deployDir” in the clean task becasue other tasks will be adding and cleaning their content from the deplyDir.

(Peter Niederwieser) #2

Unless you specify at least one output, Gradle will assume that outputs are out-of-date. You’d probably have to use ‘outputs.upToDateWhen { … }’ and interpret the absence of the files/dirs to be deleted as an up-to-date output. Anyway, I don’t think there is any benefit in declaring inputs and outputs for the ‘clean’ task.

(binyan357) #3

Well I suppose seeing the ":clean Up-To-Date " is the same as seeing the green bar in junit, it just feels good. Nonetheless, using upToDateWhen { … } has worked. Thanks.