Bazel "this rule is missing dependency declarations" (strict deps) in CI
Bazel enforces strict deps: a target may only use files provided by its direct dependencies. It found a file consumed by the rule that comes from a target not listed in deps, and names both the file and the dependency to add.
What this error means
A build fails with "this rule is missing dependency declarations for the following files included by ..." and often a hint like "Please add the following dependencies: //bar:baz".
ERROR: /home/runner/work/app/app/foo/BUILD.bazel:3:11: this rule is missing
dependency declarations for the following files included by 'foo/a.cc':
'bar/baz.h'
Please add the following dependencies: //bar:bazCommon causes
A transitive dependency was used directly
The file comes from a target you get transitively, but strict deps requires it as a direct entry in this rule deps.
A new include without a matching deps edge
Code added an include from another package without updating deps, so the file is used but undeclared.
How to fix it
Add the suggested dependency
- Copy the label from the "Please add the following dependencies" hint.
- Add it to the target deps in the BUILD file.
- Re-run so the direct dependency now covers the used file.
cc_library(
name = "lib",
srcs = ["a.cc"],
deps = ["//bar:baz"],
)Automate deps edits with a fixer
For large monorepos, a build-file fixer can add missing deps from the compiler-reported includes automatically.
bazel build //foo:lib --experimental_strict_java_deps=errorHow to prevent it
- Declare a direct deps edge for every file a target uses.
- Do not rely on transitive dependencies to satisfy includes.
- Keep strict deps set to error so gaps fail fast in CI.