修复/解决bazel包冲突的选项是什么?



我看到以下错误:

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
package with this path is linked.

@org_golang_google_genproto//googleapis/api/annotations:annotations通过:

@com_github_uber_cadence//service/history:go_default_library
@com_github_uber_cadence//service/history:history
@com_github_uber_cadence//common/resource:resource
@com_github_uber_cadence//common/archiver/provider:provider
@com_github_uber_cadence//common/archiver/gcloud:gcloud
@com_github_uber_cadence//common/archiver/gcloud/connector:connector
@com_google_cloud_go_storage//:storage
@org_golang_google_genproto//googleapis/iam/v1:iam
@org_golang_google_genproto//googleapis/api/annotations:annotations

@org_golang_google_genproto//googleapis/api/annotations:annotations可以被@go_googleapis//google/api:annotations_go_proto禁用或遮蔽吗?如果有,怎么做?

选项一:

通过在repositories.bzl文件中使用适当的gazelle:resolve指令来更改使用@org_golang_google_genproto//googleapis/api/annotations@go_googleapis//google/api:annotations_go_proto:

go_repository(
name = "com_google_cloud_go",
build_directives = [
# @go_googleapis is the modern version of @org_golang_google_genproto
# use @go_googleapis to avoid dependency conflicts between the two
"gazelle:resolve go google.golang.org/genproto/googleapis/iam/v1 @go_googleapis//google/iam/v1:iam_go_proto",  # keep
],
…
)
go_repository(
name = "com_google_cloud_go_storage",
build_directives = [
# @go_googleapis is the modern version of @org_golang_google_genproto
# use @go_googleapis to avoid dependency conflicts between the two
"gazelle:resolve go google.golang.org/genproto/googleapis/iam/v1 @go_googleapis//google/iam/v1:iam_go_proto",  # keep
"gazelle:resolve go google.golang.org/genproto/googleapis/type/expr @go_googleapis//google/type:expr_go_proto",  # keep
"gazelle:resolve go google.golang.org/genproto/googleapis/api/annotations @go_googleapis//google/api:annotations_go_proto",  # keep
],
…
)

下面也可以,但我更喜欢上面的,因为它使用了较新的库:

通过在根BUILD文件中使用适当的gazelle:resolve指令来更改使用@go_googleapis//google/api:annotations_go_proto@org_golang_google_genproto//googleapis/api/annotations:

# gazelle:resolve go google.golang.org/genproto/googleapis/api/annotations @org_golang_google_genproto//googleapis/api/annotations

我考虑过的其他选择和我没有选择的原因:

  1. 升级到最新的@com_google_cloud_go_storage。没有选择这个选项,因为最新版本(v1.24.0在这篇文章的时候)仍然使用@org_golang_google_genproto
  2. 升级@com_google_cloud_go_storage以使用@go_googleapis。没有选择这个选项,因为它看起来太难合并了。
  3. repo_mapping = {"@org_golang_google_genproto" : "@go_googleapis"}forcom_google_cloud_go_storage。没有选择这个选项,因为@go_googleapis不是@org_golang_google_genproto的直接替代品(@go_googleapis使用前缀google,而@org_golang_google_genproto使用前缀googleapis)。
  4. "gazelle:exclude **/common/archiver/gcloud/**"forcom_github_uber_cadence。没有选择这个选项,因为common/archiver/provider依赖common/archiver/gcloud
  5. go_googleapis的字冠从google设置为googleapis。我没有选择这个选项,因为它打破了那些熟悉go_googleapis标准实践的人的期望。

最新更新