Skip to content

PrintTask is @CacheableTask but has no annotated inputs, then build cache serves wrong/stale content #95

Description

@juan-rojas-affirm

PrintTask (backs printVersion, printSemVersion, printInfoVersion, printChangeLog) is @CacheableTask, but none of the properties that determine its output — the per-task printout closure, or the git state (HEAD, tags, dirty status) it reads — are annotated as Gradle inputs. file is @OutputFile, not @input. Since the cache key is derived from inputs, not outputs, every PrintTask instance, for every commit, hashes to the same key.

Result: with org.gradle.caching=true, whichever task runs first (e.g. printChangeLog) poisons the shared cache entry, so a later printVersion run gets served its content instead of its own — or, even across two different task registrations, the same task run against a different commit can return a stale cached result.

Impact: Our release pipeline runs printChangeLog --file=... releaseVersion then printVersion --file=... as separate ./gradlew invocations sharing a CI agent's build cache. printVersion's output file ended up containing printChangeLog's changelog markdown instead of a semver string.

Probably the easiest and safest fix is to just drop @CacheableTask (or mark it @DisableCachingByDefault). Alternatively, it may be worth checking whether the actual inputs can be identified and annotated, to keep caching correct instead of dropping it.
Filing rather than sending a PR since the right tradeoff here seems like a maintainer call. Happy to help validate once there's a direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions