Setting Task.outputs breaks rebuild after dependency changes


#1

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.


(Peter Niederwieser) #2

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?


#3

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?


#4

My guess was correct.

SOLVED with:

inputs.files project(':other:proj').tasks.myDepTask

(Peter Niederwieser) #5

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.


(Peter Niederwieser) #6

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.


#7

Correct … I wrote it wrong. I do have

inputs.file

#8

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.


(Peter Niederwieser) #9

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.