I noticed that if I configure a task with
outputs.file 'dist/my-proj.jar'
, then the task will no longer rerun if a dependency of the task is changed. Removing the
outputs
configuration causes gradle to behave correctly.
Is this a bug, or is there something that I am doing incorrectly.
What exactly do you mean by “if a dependency of the task is changed”? Did you declare any inputs for the task? Does it use a built-in task type or a custom one?
First off, removing ‘outputs’ from the configuration will just cause the task to run every time. So this is not a working solution.
Sorry I was not more specific. For the dependency of the task … I mean using the ‘dependsOn’ configuration, not ‘inputs’. I declared the dependency on the task using
dependsOn project(':other:proj').tasks.myDepTask
I also have set tine inputs to
inputs 'src/'
inputs 'resources/'
The inputs defines work correctly, causing a re-exeuction of the task when files change.
Maybe I also have to manualy add the files of the dependsOn task to the ‘inputs’? I figured gradle would do this automatically?
My guess was correct.
SOLVED with:
inputs.files project(':other:proj').tasks.myDepTask
Those input declarations look like no-ops. It’s ‘inputs.file’, ‘inputs.files’, or ‘inputs.dir’ (for file related inputs). In general, a task doesn’t re-run if a dependency changes (I guess you are referring to the outputs of the depended-on task), but if one of its inputs changes or its previous outputs are no longer available.
It’s the other way around. Gradle can often infer task dependencies from input configurations. When a task is implemented as a class (such as for the built-in tasks), the inputs are defined by the class, and all that’s left to do is “normal” configuration of the task.
Correct … I wrote it wrong. I do have
inputs.file
What is the other way around? Let me know if there is a better way to do this? I don’t know what you mean by ‘“normal” configuration’ … see my solution below.
Gradle doesn’t infer inputs from task dependencies, but task dependencies from inputs. Task classes typically already declare which of their properties are inputs and which are outputs. Hence you just have to configure these properties, and not (additionally) ‘inputs.files’ etc.