我正在使用 bazel 4.1.0 来构建项目。当前设置:
go.mod 文件
...
github.com/mwitkow/go-proto-validators v0.3.2 // indirect
...
工作区文件
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
load("//:repositories.bzl", "go_repositories")
go_repositories()
在 repositories.blz 文件中
...
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",
)
....
在学生/api.v1/api.proto 文件中
import "google/api/annotations.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
运行bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=repositories.bzl%go_repositories -prune=true
后bazel run //:gazelle
它生成students/api.v1/BUILD.bazel文件
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",
],
)
当我运行时bazel build //...
,它会产生错误
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
我想让构建工作没有错误。非常感谢您的帮助。我认为在BUILD.bazel
文件中,//github.com/mwitkow/go-proto-validators:validators_proto
应该是@github.com/mwitkow/go-proto-validators:validators_proto
,@go_googleapis//google/api:annotations_proto
但它只是一个模糊的想法。