bazel-contrib / bazel-contrib/rules_go

Bazel build fails: protoc-gen-validate requires @rules_java but repository not found when using Bzlmod

Open
#4,459 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

I’m trying to build a Go monorepo with Bazel + Gazelle + rules_go (Bzlmod enabled), but my build fails with the following error:
```
ERROR: error loading package '@@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate//validate':
Unable to find package for @@[unknown repo 'rules_java' requested from @@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate]//java:defs.bzl:
The repository '@@[unknown repo 'rules_java' requested from @@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate (did you mean 'rules_cc'?)]'
could not be resolved: No repository visible as '@rules_java' from repository '@@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate'.

ERROR: /.../external/gazelle++go_deps+com_github_cncf_xds_go/xds/data/orca/v3/BUILD.bazel:3:11:
error loading package '@@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate//validate':
Unable to find package for @@[unknown repo 'rules_java' ...]

```
It seems that protoc-gen-validate indirectly requires @rules_java, but Bazel (with Bzlmod) doesn’t provide it automatically in this context.

---
My Setup

BUILD.bazel
```
load("@gazelle//:def.bzl", "gazelle")

# gazelle:prefix github.com/my-org/infini-services-go
gazelle(name = "gazelle")

# gazelle:resolve go github.com/envoyproxy/protoc-gen-validate/validate @protoc-gen-validate//validate:go_default_library
# gazelle:resolve go github.com/cncf/xds/go/xds/type/v3 @xds//xds/type/v3:go_default_library

```
WORKSPACE

```
workspace(name = "infini_services_go")

```

MODULE.bazel

```
module(name = "infini_services_go")

bazel_dep(name = "rules_go", version = "0.57.0")
bazel_dep(name = "gazelle", version = "0.45.0")
bazel_dep(name = "platforms", version = "1.0.0")

# Extra deps I tried adding manually
bazel_dep(name = "rules_cc", version = "0.1.1")
bazel_dep(name = "rules_java", version = "8.15.2")
bazel_dep(name = "bazel_skylib", version = "1.8.1")
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.8.1")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.0")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")

go_deps.gazelle_default_attributes(
directives = ["gazelle:proto disable_global"],
)

use_repo(
go_deps,
"com_github_envoyproxy_protoc_gen_validate",
"com_github_cncf_xds_go",
# ... other deps ...
)

```

.bazelrc
```
common --enable_bzlmod
common --repo_env=GOPROXY=https://proxy.golang.org,https://goproxy.io,direct
common --repo_env=GOSUMDB=sum.golang.org
build --enable_platform_specific_config
build --jobs=8
build --verbose_failures
build --@rules_go//go/config:pure
build --@rules_go//go/config:tags=purego

```

Contributor guide

Open the contributing guide

Research direction

Start with MODULE.bazel and the go_deps configuration, then reproduce the reported build error using the repository's Bazel invocation. Trace how com_github_envoyproxy_protoc_gen_validate refers to @rules_java under Bzlmod and compare that with the declared dependencies and use_repo entries. Done means the affected xds package loads and the Go build proceeds without the unknown-repository error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.