Gradle build cache: stale entry detection for externally modified files
26.5K reputation · 26 Nov 2022, 15:23 UTC
Goal: Ensure build cache invalidates when files change outside declared inputs.
In many projects, external tools or manual edits modify files that are normally outputs of a Gradle task. Since the build cache only hashes declared task inputs, these external changes are invisible to Gradle, leading to stale artifacts being reused.
Constraints: Gradle’s current cache policy does not provide automatic detection or eviction for such changes, and the local cache has no retention policy. Users must manually clean the cache, risking removal of valid entries.
Questions:
1) Does Gradle offer a configuration to monitor file modification timestamps for cache invalidation?
2) Can we declare external files as implicit inputs or use a custom input mechanism?
3) Is there a way to set a retention or eviction policy for the local build cache?