Skip to content

Fix lockfile refs for binary-less and cached artifacts#1588

Open
shs96c wants to merge 3 commits into
bazel-contrib:masterfrom
shs96c:shs/v3-lockfile-aggregator-tolerance
Open

Fix lockfile refs for binary-less and cached artifacts#1588
shs96c wants to merge 3 commits into
bazel-contrib:masterfrom
shs96c:shs/v3-lockfile-aggregator-tolerance

Conversation

@shs96c

@shs96c shs96c commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Some Gradle Module Metadata resolutions can produce coordinates that are useful for dependency graph shape but do not correspond to an emitted jar target. This exposed two ways a freshly repinned lockfile could be generated successfully but fail when Bazel later tried to use it:

  1. A binary-less aggregator coordinate could remain in repositories or dependency edges even though the artifact key was not emitted in artifacts.
  2. A POM-only Gradle artifact could be recorded as the known local path for a jar coordinate, causing the lockfile to store the POM checksum for a jar URL. The next Bazel fetch then failed because the downloaded jar did not match the pinned checksum.

This changes lockfile generation to keep the emitted artifact set and all repository/dependency references consistent.

It also tightens the Gradle resolver and downloader path handoff so a local file is only used as the known artifact path when its filename matches the coordinate being resolved. That prevents .pom files from being hashed as jars while still allowing real jar artifacts, including classified jars such as jar:unshaded, to be pinned and consumed normally.

shs96c and others added 2 commits June 11, 2026 12:26
A binary-less aggregator coordinate -- one with no artifact of its own,
such as a Gradle module-metadata umbrella, an `available-at` redirect, or
a `<packaging>pom</packaging>` POM -- can share its `group:artifact` key
with a classified sibling that owns the only shasum. When it does, the
lock file records that key with shasums like `{"unshaded": ...}` and no
`jar` entry, so neither AbstractMain.calculateArtifactHash nor its
Starlark mirror in v3_lock_file.bzl reconstructs the plain
`group:artifact` key. The plain key still appears in the `repositories`
and `dependencies` sections, so walking those sections threw a
NullPointerException (Java) and failed with "key not found in dictionary"
(Starlark) when resolving real repositories.

- Skip artifacts with no reconstructed entry when assigning repositories
  and dependencies during hashing; they contribute no hashable artifact.
  The Java and Starlark computations are kept in lock-step so the stored
  __RESOLVED_ARTIFACTS_HASH still matches.
- Filter dependency edges that point at a coordinate with no generated
  target (_artifact_keys + _filter_dependency_targets) so the BUILD-file
  generator never emits a dangling target reference.

Adds a Java regression test reproducing the exact lock-file shape and
Starlark unit tests for both guards (and registers the previously unwired
tests/unit/v3_lock_file_test.bzl suite).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@shs96c shs96c requested review from cheister and jin as code owners June 11, 2026 15:10
@shs96c shs96c changed the title Fix v3 lockfile refs for binary-less and cached artifacts Fix lockfile refs for binary-less and cached artifacts Jun 11, 2026
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.

1 participant