使用 Bazel 构建 Go 无法解析存储库

问题描述 投票:0回答:2

我按照“使用 Bazel 构建 Go 服务”youtube 中的步骤,创建了一个具有依赖项的简单项目,但无法构建并出现错误:

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

文件结构

项目:https://gitlab.com/mvfwd/issue-bazel-go

步骤

参见 .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 ...
    • 因错误而失败

认为可能是因为“go-randomdata”中的破折号,所以添加了另一个非破折号依赖项(github.com/stretchr/testify/assert),遇到了同样的问题。

我做错了什么?我是不是错过了什么?

UPD: 解决方案是使用以下组合

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

此处所述。

update-repos...
部分将使用所有必要的依赖项更新 WORKSPACE。

go bazel bazel-rules
2个回答
4
投票

解决方案是使用以下组合

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

此处所述。

update-repos...
部分将使用所有必要的依赖项更新
WORKSPACE
文件。


0
投票

这是一个 Go 程序的骨架:https://github.com/filmil/bazel-go-basic

它具有 Go 程序的所有基本元素。

© www.soinside.com 2019 - 2024. All rights reserved.