I have a task that only needs to run when dependencies change. It alters an external file, but it doesn’t need to run again until the dependencies change, no matter what other external program also modifies that external file.
This part works OK - to a point. If the output file hasn’t changed and the dependencies haven’t changed, nothing happens. If the dependencies change, then the file is regenerated. But, if the output file is changed externally, Gradle still marks it as out of date.
So, now I’m trying to tell Gradle that the output file doesn’t matter: ‘task.outputs.files.from.clear()’. This “works” a little too well: now Gradle is complaining that no output files are specified, so it’s going to execute the task no matter what.
How do I tell Gradle to ignore the output file and base its up-to-date decision completely on the input properties?
You can provide a closure to the task for customizing the up-to-date logic. This should mark the output as always up to date, no matter what, but similarly you could just do a File.exists() test to gate execution.
Providing a ‘{ true }’ closure to upToDateWhen just disables the task. Checking to see if the file exists means it’ll only execute once. Neither one of those is what I need.