How to get bazel/gazelle go_repository imports past go vet

697 views Asked by At

I'm using bazel/gazelle to pull in some external git repositories. For example:

go_repository(
    name = "com_github_pkg_errors",
    importpath = "github.com/pkg/errors",
    sum = "h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=",
    version = "v0.8.1",
)

My go file would just import github.com/pkg/errors like normal. Problem comes when I run go vet on my file. It would complain that no such package exists under GOROOT or GOPATH. This repo is located in my bazel cache. ~/.cache/bazel/.../external/com_github_pkg_errors

How can I resolve this?

1

There are 1 answers

0
Vishrant On
  1. You have to specify the dependency in go.mod
require (
    github.com/pkg/errors v0.8.1
)
  1. In the BUILD.bazel file of your project, specify go_library with dep
go_library(
    name = "project_lib",
    srcs = [],
    importpath = "github.com/pkg/errors",
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_pkg_errors",
    ],
)