gobazelbazel-rules

Building Go with Bazel could not resolve a repository


I am following the steps from "Building Go Services With Bazel" youtube and created a simple project with dependency that fails to build with an error:

ERROR: /builds/mvfwd/issue-bazel-go/cmd/BUILD.bazel:3:11: no such package '@com_github_pallinder_go_randomdata//': The repository '@com_github_pallinder_go_randomdata' could not be resolved and referenced by '//cmd:cmd_lib'
ERROR: Analysis of target '//cmd:cmd' failed; build aborted: Analysis failed
INFO: Elapsed time: 1.263s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 165 targets configured)
FAILED: Build did NOT complete successfully (1 packages loaded, 165 targets configured)

Whole log

Versions

$ bazel --version
bazel 4.1.0

$ go version
go version go1.17 linux/amd64

File structure

Project: https://gitlab.com/mvfwd/issue-bazel-go

Steps

See .gitlab-ci.yml

Thought it might be because of the dash in "go-randomdata", so added another non-dashed dependency (github.com/stretchr/testify/assert), got the same issue.

What am I doing wrong? Am I missing something?

UPD: Solution was to use the following combination

$ bazel run //:gazelle
$ bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=deps.bzl%go_dependencies
$ bazel run //:gazelle

As described here. update-repos... part would update WORKSPACE with all the necessary dependencies.


Solution

  • Solution was to use the following combination

    $ bazel run //:gazelle
    $ bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=deps.bzl%go_dependencies
    $ bazel run //:gazelle
    

    As described here.

    update-repos... part would update WORKSPACE file with all the necessary dependencies.