Unexpected behavior of `--override_repository=...` with bazel modules

27 views
Skip to first unread message

Filip Filmar

unread,
Oct 11, 2025, 10:51:35 PM (3 days ago) Oct 11
to bazel-discuss

I was looking for ways to compose local repositories in the bazel modules world, without changing any checked-in files.

I was experimenting on my repo bazel-rules-bid, and I wanted to locally override the dependency gotopt2. See at https://github.com/filmil/bazel-rules-bid/blob/main/MODULE.bazel#L11

I did this by adding the following to my user.bazelrc:

build --override_repository=+bazel_rules_bid_extension+gotopt2=/home/filmil/code/bazel/gotopt2

But, while this “worked” in the sense that the override was honored, I got the error:

╰─>$ bazel build //...
ERROR: error loading package '@@+bazel_rules_bid_extension+gotopt2//': Unable to find package for @@[unknown repo 'gazelle' requested from @@+bazel_rules_bid_extension+gotopt2]//:def.bzl: The repository '@@[unknown repo 'gazelle' requested from @@+bazel_rules_bid_extension+gotopt2]' could not be resolved: No repository visible as '@gazelle' from repository '@@+bazel_rules_bid_extension+gotopt2'.
ERROR: /home/filmil/code/bazel/bazel-rules-bid/build/BUILD.bazel:16:8: error loading package '@@+bazel_rules_bid_extension+gotopt2//': Unable to find package for @@[unknown repo 'gazelle' requested from @@+bazel_rules_bid_extension+gotopt2]//:def.bzl: The repository '@@[unknown repo 'gazelle' requested from @@+bazel_rules_bid_extension+gotopt2]' could not be resolved: No repository visible as '@gazelle' from repository '@@+bazel_rules_bid_extension+gotopt2'. and referenced by '//build:gen_docker_run'
ERROR: Analysis of target '//build:gen_docker_run' failed; build aborted: Analysis failed
INFO: Elapsed time: 1.681s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

I noticed that the error goes away if I add the appropriate bazel_dep in bazel-rules-bid. Is this expected? If yes, is there a way to override the repo in a way that handles the dependencies? Do I have to use bazel_dep for that?

Thanks,
F

Filip Filmar

unread,
Oct 11, 2025, 10:55:11 PM (3 days ago) Oct 11
to bazel-discuss

I also tried this if I bring in the repo gotopt2 using bazel_dep(...), and changing the override repository to:

build --override_repository=gotopt2+=/home/filmil/code/bazel/gotopt2

but the same behavior remains.

F

Fabian Meumertzheim

unread,
3:04 AM (13 hours ago) 3:04 AM
to Filip Filmar, bazel-discuss
The overridden repository still uses the same repository mapping (mapping apparent names to canonical names): either that of the module owning the extension that declares the repo or that describes by its MODULE.bazel file if overriding a module repo. You still have to add `bazel_dep`s, otherwise it isn't clear what `gazelle` should refer to.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/bazel-discuss/CAKaOXii-z7Jod0RnfZHZXMm-cesBPNKuB%3D7rzjP%3DQYksFS9MVA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages