Basic question on outputs management

(Eric Cavailles) #1


Here is a use case to illustrate my problem:
-> I have a task that creates a file : build/result/toto.txt
-> The output of this task is the directory build/result

When I run the task, the file toto.txt is created.
When I run the task again, the task is UpToDate => OK

If I create a file build/result/titi.txt and re-run the task, the task is UpToDate because titi.txt is not considered as an output of the task because it has not been generated by the first run of the task.

Question 1: Is there a way to force gradle to automatically re-execute the task in this condition (i.e when output.dir changes even if the change affects something that has not been generated by the task) ?
I know the --rerun-tasks option but this is not really what I want. I want gradle to decide on its own.

Now let’s say that I modify the task to generate both toto.txt and titi.txt.
When I run the task, both files are overwritten
When I run the task again, the task is UpToDate => OK
If I modify titi.txt, the task is UpToDate because the file has never been generated by the task (It was existing before the first task run).

Question 2: Is there a way to force gradle re-evaluating task outputs without taking into account already existing files ? In other words, is there a way to make gradle understand that tasks outputs are really toto.txt & titi.txt without removing and re-generating them ?

Thanks for your help,

(Eric Cavailles) #2

Up, !
Any advice ?


(Joshua Street) #3

I’m having trouble understanding your fist use case. I’m trying to come up with a situation where you have a file in the output folder of a task that the task itself never generated and can’t really think of how this would happen, or need to happen for that matter.

As for your second use case, I could understand wanting to run the task again if one of the outputs was changed, and I thought that was what gradle did automatically, because the file had changed and no longer matched the hash for the task output. Are you asking for gradle to only regenerate files that were missing and not to touch those that exist?

It sounds like you want gradle to populate a folder with some files and only generate them if necessary, leaving them if they are already there?

There are several ways you can hook into a task to help it determine if it should run. I recommend looking at the documentation on defining task inputs and outputs. You probably need to dynamically determine outputs of this task based on existing files within the build folder.