Skip to content

[1.x] fix: Invalidate update cache across commands when dependencies change#8593

Merged
eed3si9n merged 2 commits intosbt:1.12.xfrom
calm329:fix/8357-transitive-update-invalidation-1.x
Jan 20, 2026
Merged

[1.x] fix: Invalidate update cache across commands when dependencies change#8593
eed3si9n merged 2 commits intosbt:1.12.xfrom
calm329:fix/8357-transitive-update-invalidation-1.x

Conversation

@calm329
Copy link
Copy Markdown
Contributor

@calm329 calm329 commented Jan 20, 2026

Summary

Backport of #8501 to 1.x: Fix update cache invalidation across sbt command invocations when a dependency's dependencies change.

Problem

When project A's dependencies changed and A was compiled in one command, project B (depending on A) would not invalidate its update cache in a subsequent command. This caused stale classpaths.

The root cause was that depsUpdated only checked !stats.cached, which only detected fresh resolves within the same command. When a dependency was served from cache (even if resolved fresh in a previous command), cached was marked true by markAsCached, causing incorrect cache reuse.

Debug scenario from issue:
sbt:aaa> clean
sbt:aaa> a/compile
sbt:aaa> show itTests/depsUpdated
[info] * false <-- BUG: should be true

Solution

Instead of relying on the transient cached flag, we now hash the resolved module IDs (organization, name, revision) from each transitive dependency and include these hashes in the cache key (UpdateInputs).

  • When any dependency's resolved versions change, the hash changes → cache is invalidated
  • When dependencies stay the same, the hash stays the same → cache is reused correctly

Note: Unlike 2.x which adds a stamp field to UpdateStats in librarymanagement, this 1.x backport achieves the same goal without requiring changes to the external librarymanagement library.

Changes

  • Change UpdateInputs type to include Vector[Long] for transitive dependency hashes
  • Change depsUpdated: Boolean parameter to transitiveUpdates: Seq[UpdateReport]
  • Remove !depsUpdated check from upToDate (now covered by input hash)
  • Hash resolved module IDs from transitive updates for cache invalidation
  • Add scripted test i8357-transitive-update-invalidation

Test plan

  • Compiles successfully
  • Run scripted test: scripted dependency-management/i8357-transitive-update-invalidation

Fixes #8357
Ref #8592

Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eed3si9n eed3si9n changed the title fix: Invalidate update cache across commands when dependencies change [1.x] fix: Invalidate update cache across commands when dependencies change Jan 20, 2026
@eed3si9n eed3si9n merged commit 08ab372 into sbt:1.12.x Jan 20, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants