Bazel - BUILD not referencing external dependency

1.1k views Asked by At

I'm trying to run some grpc tests with bazel. I'm using "google.golang.org/grpc/credentials/insecure" to dial insecurely.

When running bazel test ..., I get the following error:

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'

I am generating my BUILD files with gazelle which outputs this for the 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",
    ],
)

My go.mod file contains the dep: google.golang.org/grpc v1.47.0

My deps.bzl is auto generated by gazelle:

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

What am I missing?

1

There are 1 answers

0
SG_Bazel On BEST ANSWER

In the WORKSPACE, the local go_repositories() generated by gazelle must be called before gazelle_dependencies(), which will define an ancient version of org_golang_google_grpc if it doesn't exist yet and the local go_repository for the newer version will be silently ignored. Reference