You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Bazel至8.x遇platforms仓库解析错误,求修复方案

Bazel 7.x升级8.x后平台仓库解析错误的解决方法

升级Bazel到8.x后构建出现如下错误:

no such package '@@[unknown repo 'platforms' requested from @@]//os': The repository '@@[unknown repo 'platforms' requested from @@]' could not be resolved: No repository visible as '@platforms' from main repository

问题原因

Bazel 8.x不再默认提供platforms仓库,而你使用的rules_go 0.52.0依赖该仓库,因此需要显式引入。

修改配置步骤

1. 更新 module.bazel

在文件开头添加platforms依赖:

module(
    name = "REDACTED",
    version = "0.1.0",
)

# 添加platforms仓库依赖,版本选择与rules_go兼容的0.0.10
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_go", version = "0.52.0")
bazel_dep(name = "gazelle", version = "0.41.0")

# 其余配置保持不变
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.nogo(nogo = "//:my_nogo")
go_sdk.download(version = "1.23.4")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(go_deps, "com_github_aws_aws_sdk_go_v2", "com_github_aws_aws_sdk_go_v2_config", "com_github_aws_aws_sdk_go_v2_service_sesv2", "com_github_go_acme_lego_v4", "com_github_jackc_pgx_v5", "com_github_jub0bs_cors", "com_github_prometheus_client_golang", "com_github_prometheus_client_model", "com_github_prometheus_common", "io_opentelemetry_go_otel", "org_golang_google_protobuf", "org_golang_x_crypto", "org_golang_x_net")

2. 同步依赖并重新构建

执行以下命令拉取新依赖并验证构建:

bazel sync
bazel build //...

额外说明

  • 如果后续仍有兼容性问题,可以尝试升级rules_go到最新稳定版(需确认与Bazel 8.x兼容)
  • .bazelrc中的平台配置无需修改,@rules_go//go/toolchain已封装了所需的平台定义

内容的提问来源于stack exchange,提问作者Little Code

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 19:36:13