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)
$ bazel --version
bazel 4.1.0
$ go version
go version go1.17 linux/amd64
Project: https://gitlab.com/mvfwd/issue-bazel-go
See .gitlab-ci.yml
go mod init gitlab.com/mvfwd/issue-bazel-go
go.mod
go mod tidy
go.sum
bazel run //:gazelle
cmd/BUILD.bazel
bazel build ...
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 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.