Can I update a task property during execution step?

my task has a property like:
@OutputFiles ListProperty<RegularFile> outFiles;

during the step of execution time, i want to add entries into the list but i got:

The value for this property is final and cannot be changed any further.

My purpose is to update the property and another task was connected by @InputFiles property
so that it will get what exactly created during the upper-level task.

Thanks in advance.

Hi,

the location of the output files needs to be known prior to task execution. It is more about configuring the task where the outputs should end up (aka in this directory), instead of the task reporting back what it produced (aka I created file A, B and C in the given output directory).

Normally, the output of a task is a single file or an output directory where the files should be created. Can you use something like an output directory? Why do you need to add the output files during execution?

Cheers,
Stefan

Let’s say Task A depends on Task B. Task B outputs some files into some directory. I want Task A know the Task B output state changed(include content changes, removed or new added files) so that Task A could re-run based on that output file. You mean I should use ListProperty instead of ListProperty? Does the directory one can automatically report the change to Task A?

You should configure task B to have an output directory, where it creates the files. Then task A should have the output directory of task B as an input directory. Task A itself should be an incremental task and use InputChanges in its task action. The you can query the InputChanges object about what has changed since the last build.

See the user manual for more documentation and samples for incremental tasks: https://docs.gradle.org/current/userguide/custom_tasks.html#incremental_tasks

1 Like

I have verified your solution, it works! Thank you very much!! :slight_smile: