Multiple copies package conflict error between rules_go and golang_protobuf
What version of rules_go are you using?
0.28.0
What version of gazelle are you using?
0.23.0
What version of Bazel are you using?
4.2.1
Does this issue reproduce with the latest releases of all the above?
Yes
What operating system and processor architecture are you using?
darwin/amd64
Any other potentially useful information about your toolchain?
com_github_golang_protobuf -> v1.5.2
What did you do?
I am trying to use the Bazel tool to build a large monorepo. Repo has pre-generated proto files with gRPC services too.
Commands used to build the repository.
bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=deps.bzl%go_dependencies -build_file_proto_mode=disable_global -prune
bazel run //:gazelle
bazel build //pkg_name
What did you expect to see?
No error and successful build
What did you see instead?
package conflict error
link: package conflict error: github.com/golang/protobuf/protoc-gen-go/descriptor: multiple copies of package passed to linker:
@com_github_golang_protobuf//protoc-gen-go/descriptor:descriptor
@io_bazel_rules_go//proto/wkt:descriptor_go_proto
Set "importmap" to different paths or use 'bazel cquery' to ensure only one
package with this path is linked.
Please suggest debugging steps to share more details about the issue WORKSPACE.txt BUILD.txt
Can you create a minimal repo that can reproduce the issue?
I've hit a similar bug:
link: package conflict error: google.golang.org/genproto/googleapis/api/annotations: multiple copies of package passed to linker:
@go_googleapis//google/api:annotations_go_proto
@org_golang_google_genproto//googleapis/api/annotations:annotations
Set "importmap" to different paths or use 'bazel cquery' to ensure only one
The problem occurred after upgrading cloud.google.com/go/storage in go.mod. The first version that break seems to be: v1.18.2. If the problem is between 1.18.1 and 1.18.2 then it's probably this PR https://github.com/googleapis/google-cloud-go/commit/acece394a38843f4355a82d0abab1e41994eca12. I'm not confident because I can't build a v1.17.0 due to an unrelated error that might be masking the same error.
I've worked around the issue by keeping cloud.google.com/go/storage at v1.16.0.
The relevant go.mod versions to cause the failure:
cloud.google.com/go/storage v1.18.1
google.golang.org/genproto v0.0.0-20220304144024-325a89244dc8
Similar issues:
- https://github.com/bazelbuild/rules_go/issues/2818
- https://github.com/bazelbuild/rules_go/issues/2558
- https://github.com/bazelbuild/bazel-gazelle/issues/941
This is an ongoing annoyance that has never been resolved.