I have a task which modifies a file in place, so the task file property is annotated with both @InputFile and @OutputFile, but in gradle 4.5 this generates a warning about conflicting property types. How can I avoid it? The file must be modified in place, for various reasons.
For details, it reads the file, modifies it according to certain rules, then writes it back out.
The easiest thing to do would be to remove all @OutputXXX annotations (or all @InputXXX or @OutputXXX annotations). The task can never be incremental/up-to-date, so the annotations aren’t useful.
The task uses its own OnlyIf logic to check if the modification is in place, so it will skip it if everything is up to date, but it needs to know If someone else has modified the file too. When I wrote it, some time ago, the combination of input/output/onlyif was the only thing that worked, but I’ll take another look at it.
So I want the task to run if someone else has modified it, or if the someOption property has changed, but only if it doesn’t already contain the right option. Other tasks depending on changes in the configFile should always run if it’s been modified. After removing @OutputFile and extending my test suite, it seems like things still work, so I guess I’m good for now.
You can even go further now and annotate the task as @UntrackedTask.
But yeah, a task that modifies a file in-place can hardly ever be up-to-date, so input and output annotations make little sense.
And in most situations it still is most probably not a good idea to modify files in-place.
If they are output files of another task it is even worse as you then also invalidate that tasks result.
But for something like a version update task, probably not much changed.