Why does my task run even though non of its inputs has changed?

I have a task that checks that all i18n properties defined in a properties files are actually used somewhere. It needs to be run only if any of the source files or the properties files have changed. However, when I only specify these files as the tasks ‘inputs’ the task runs even if none of them has changed. If I also specify them as ‘outputs’, the task recognizes that it is up-to-date.

I would rather not artificially specify the input files as ‘outputs’.

It seems it would be useful to have the task consider itself up-to-date when no input files have changed if no other criteria are given.

Is there a way to work around this, for example using the upToDateWhen closure to check whether the inputs have changed. (I looked at the javadoc but didn’t see any methods on the TaskInputs object to do that).

This should do the trick:

task.outputs.upToDateWhen { true }

The current behavior makes sense to me. If you don’t provide Gradle with the necessary (output) information, it would be risky to assume that things are up-to-date. It’s better to err on the safe side.

That was easy:-) Thanks. Prompted me to try


which also works.

I guess it’s a matter of taste whether the presence of outputs should be required. In that case specifying inputs and no outputs should throw an exception in my view rather than silently ignore the inputs. On the other hand there are some tasks (notably checks) that have no output, so specifying output files or constant conditions seems arbitrary in these cases.

Most check tasks do have outputs because they generate some kind of report.