登录
首页 >  Golang >  Go问答

Bazel - BUILD 文件中不包含外部依赖

来源:stackoverflow

时间:2024-03-18 21:42:31 411浏览 收藏

在使用 Bazel 运行 gRPC 测试时,如果遇到“no such package”错误,可能是因为外部依赖项(如“google.golang.org/grpc/credentials/insecure”)的 BUILD 文件丢失。通常,此类文件是由 Gazelle 自动生成的,但如果没有正确调用 Gazelle 生成的本地 go_repositories() 函数,则可能会导致此错误。为了解决此问题,请确保在 WORKSPACE 文件中按照正确的顺序调用 Gazelle 生成的函数,或者定义外部依赖项的旧版本。

问题内容

我正在尝试使用 bazel 运行一些 grpc 测试。 我使用 "google.golang.org/grpc/credentials/insecure" 进行不安全拨号。

运行 bazel test ... 时,出现以下错误:

no such package '@org_golang_google_grpc//credentials/insecure': build file not found in directory 'credentials/insecure' of external repository @org_golang_google_grpc. add a build file to a directory to mark it as a package. and referenced by '//go/internal/handlers/helloworld:helloworld_test'

我正在用瞪羚生成我的构建文件,它为 go_test 输出该文件

go_test(
    name = "helloworld_test",
    srcs = ["helloworld_test.go"],
    deps = [
        ":helloworld",
        "//protos/helloworld",
        "@com_github_stretchr_testify//assert",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_google_grpc//credentials/insecure",
        "@org_golang_google_grpc//test/bufconn",
        "@org_uber_go_zap//:zap",
        "@org_uber_go_zap//zaptest",
    ],
)

我的 go.mod 文件包含 dep: google.golang.org/grpc v1.47.0

我的 deps.bzl 是由瞪羚自动生成的:

go_repository(
    name = "org_golang_google_grpc",
    importpath = "google.golang.org/grpc",
    sum = "h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8=",
    version = "v1.47.0",
)

我错过了什么?


正确答案


在WORKSPACE中,必须先调用gazelle生成的本地go_repositories(),然后再调用gazelle_dependency(),这将 如果没有,请定义 org_golang_google_grpc 的旧版本 尚存在,新版本的本地 go_repository 将是 默默无视。 Reference

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《Bazel - BUILD 文件中不包含外部依赖》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>