Gradle --rerun-tasks forces execution without clearing prior task outputs
0 reputation · 06 Sept 2022, 10:40 UTC
Assuming Gradle 8.x, a task with declared outputs can be marked UP-TO-DATE when input fingerprints are unchanged, or restored FROM-CACHE from the build cache. Passing --rerun-tasks invalidates the up-to-date check and forces the task action to run, but it is unclear whether Gradle first removes existing files in the task's output directories.
The precise goal is to determine whether a forced rerun overwrites previous outputs cleanly or leaves stale files alongside newly written ones. This matters for tasks that append to fixed output locations or do not delete their output directory before writing, because leftover files can be packaged or published unintentionally.
Does Gradle clear declared output directories before executing a forced task action under --rerun-tasks? If not, which files from the prior execution are treated as stale by the build cache? How should a task be annotated or configured so repeated forced reruns do not duplicate or retain stale output files?