Bazel构建golang项目错误:no such package '@org_golang_x_tools..'

建了个demo来测试Bazel构建golang项目,项目位于D:\workspace\www\go_work\src\golang_learning,有以下文件:

golang_learning
  |__ go.mod
  |__ main.go
  |__ WORKSPACE
  |__ BUILD.bazel

各文件内容如下,Bazel的两个文件WORKSPACEBUILD.bazel按照文档来写的https://github.com/bazelbuild...
go.mod

module golang_learning

main.go

package main

import "fmt"

func main() {
    fmt.Println("Hello,world")
}


WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "io_bazel_rules_go",
    urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.16.1/rules_go-0.16.1.tar.gz"],
    sha256 = "f5127a8f911468cd0b2d7a141f17253db81177523e4429796e14d429f5444f5f",
)
http_archive(
    name = "bazel_gazelle",
    urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.15.0/bazel-gazelle-0.15.0.tar.gz"],
    sha256 = "6e875ab4b6bf64a38c352887760f21203ab054676d9c1b274963907e0768740d",
)
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
gazelle_dependencies()

BUILD.bazel

load("@bazel_gazelle//:def.bzl", "gazelle")

# gazelle:prefix github.com/example/project
gazelle(name = "gazelle")

当运行 bazel run //:gazelle的时候,出现如下错误:

PS D:\workspace\www\go_work\src\golang_learning> bazel run //:gazelle
DEBUG: C:/users/dell/_bazel_dell/4tmnaczu/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:115:5:
Auto-Configuration Warning: 'BAZEL_VC' is not set, start looking for the latest Visual C++ installed.
DEBUG: C:/users/dell/_bazel_dell/4tmnaczu/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:115:5:
Auto-Configuration Warning: Looking for VS%VERSION%COMNTOOLS environment variables, eg. VS140COMNTOOLS
DEBUG: C:/users/dell/_bazel_dell/4tmnaczu/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:115:5:
Auto-Configuration Warning: Looking for Visual C++ through registry
DEBUG: C:/users/dell/_bazel_dell/4tmnaczu/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:115:5:
Auto-Configuration Warning: Looking for default Visual C++ installation directory
DEBUG: C:/users/dell/_bazel_dell/4tmnaczu/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:115:5:
Auto-Configuration Warning: 'PROGRAMFILES(X86)' environment variable is not set, using 'C:\Program Files (x86)' as default
ERROR: Analysis of target '//:gazelle' failed; build aborted: no such package '@org_golang_x_tools//go/gcexportdata': java.io.IOException: thread interrupted
INFO: Elapsed time: 339.763s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (42 packages loaded)
FAILED: Build did NOT complete successfully (42 packages loaded)

是哪里没有配置正确?

阅读 4.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进