Make `load` ignore modules marked as `dev_dependency`
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
### Description of the feature request:
`load` should ignore modules marked as `dev_dependency` for `BUILD.bazel` files not in the root module. If a public target depends (directly or indirectly) on such module, it should error with something like "target A depends on B, but B is marked as a dev dependency".
### Which category does this issue belong to?
External Dependency
### What underlying problem are you trying to solve with this feature?
Currently, you can't have public targets in the same `BUILD.bazel` file as you're loading a dev dependency:
```python
# MODULE.bazel
bazel_dep(name = "bazel_skylib", version = "1.7.1", dev_dependency = True)
```
```python
# BUILD.bazel
load("@bazel_skylib//rules:build_test.bzl", "build_test")
genrule(
name = "genrule",
outs = ["hello"],
cmd = "echo world > $@",
visibility = ["//visibility:public"],
)
build_test(
name = "test",
targets = [":genrule"],
)
```
When trying to use `:genrule` from another module, you get an error saying the dev dependency can't be found:
```text
ERROR: error loading package '@@b~//': Unable to find package for @@[unknown repo 'bazel_skylib' requested from @@b~]//rules:build_test.bzl: The repository '@@[unknown repo 'bazel_skylib' requested from @@b~]' could not be resolved: No repository visible as '@bazel_skylib' from repository '@@b~'.
ERROR: /home/aleter01/Sandbox/dev_dependency/BUILD.bazel:1:6: error loading package '@@b~//': Unable to find package for @@[unknown repo 'bazel_skylib' requested from @@b~]//rules:build_test.bzl: The repository '@@[unknown repo 'bazel_skylib' requested from @@b~]' could not be resolved: No repository visible as '@bazel_skylib' from repository '@@b~'. and referenced by '//:genrule'
```
### Which operating system are you running Bazel on?
Linux
### What is the output of `bazel info release`?
release 7.4.0
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
```
### Have you found anything relevant by searching the web?
No, but I've [asked](https://bazelbuild.slack.com/archives/CA31HN1T3/p1738601290906689) about this in the Bazel Slack.
### Any other information, logs, or outputs that you want to share?
[Here](https://github.com/alextercete/bazel-dev-dependency-issue)'s a reproduction of the current behaviour. The current workaround seem to be to split targets which depend on the dev dependency into a separate `BUILD.bazel` file.
Contributor guide
Research direction
Start with the linked reproduction and the MODULE.bazel and BUILD.bazel examples, focusing on the load of the dev dependency and the public target that uses it. Trace how non-root modules resolve dev_dependency repositories and how indirect dependencies are checked. Done means load ignores the dev dependency where appropriate and public targets receive the requested dependency error instead of an unknown-repository error.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100