Bazel build error with third party library - no such package

1.9k views Asked by At

I'm using bazel 4.1.0 to build to project. Current set up:

go.mod file

    ...
    github.com/mwitkow/go-proto-validators v0.3.2 // indirect
    ...

WORKSPACE file

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

load("//:repositories.bzl", "go_repositories")


go_repositories()

in repositories.blz file

   ...
    go_repository(
        name = "com_github_mwitkow_go_proto_validators",
        importpath = "github.com/mwitkow/go-proto-validators",
        sum = "h1:qRlmpTzm2pstMKKzTdvwPCF5QfBNURSlAgN/R+qbKos=",
        version = "v0.3.2",
    )
  ....

in students/api.v1/api.proto file

import "google/api/annotations.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto"; 

after running bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=repositories.bzl%go_repositories -prune=true and bazel run //:gazelle

it generate students/api.v1/BUILD.bazel file

proto_library(
    name = "api_proto",
    srcs = ["api.proto"],
    visibility = ["//visibility:public"],
    deps = [
        "//github.com/mwitkow/go-proto-validators:validators_proto",
        "@go_googleapis//google/api:annotations_proto",
    ],
)

go_proto_library(
    name = "api_go_proto",
    compilers = ["@io_bazel_rules_go//proto:go_grpc"],
    importpath = "students/generated/api",
    proto = ":api_proto",
    visibility = ["//visibility:public"],
    deps = [
        "//github.com/mwitkow/go-proto-validators:validator_proto",
        "@go_googleapis//google/api:annotations_go_proto",
    ],
)

When I run bazel build //..., it produces an error

ERROR: /my-app/students/api.v1/BUILD.bazel:15:17: no such package 'github.com/mwitkow/go-proto-validators': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /my-app/github.com/mwitkow/go-proto-validators and referenced by '/students/api.v1:api_go_proto'
ERROR: Analysis of target '//students/api.v1:api' failed; build aborted: Analysis failed

I would like to make the build work without error. Thank you very much for your help. I think in BUILD.bazel file, //github.com/mwitkow/go-proto-validators:validators_proto should be @github.com/mwitkow/go-proto-validators:validators_proto, like @go_googleapis//google/api:annotations_proto but it's just a vague idea.

0

There are 0 answers