我正在try 调试CI中的以下构建错误,其中"A依赖于B,而B不能构建,因为它依赖于C."我正在构建我的数据服务,它不直接依赖于kafkaAvailMonitor or.go,这使得这个错误很难跟踪.换句话说,就是:

数据(我正在构建的内容)取决于(?)这取决于 kafkaAvailMonitor.go

对于一个开发人员来说,修复它可能看起来微不足道,他们只是"go 获取任何东西",但我不能将此作为发布过程的一部分-我必须找到添加依赖项的人,并要求他们修复它.

我知道有一些工具可以可视化依赖关系树和其他更复杂的构建系统,但这似乎是一个非常基本的问题:有没有任何方法可以查看完整的依赖关系树来查看导致构建问题的原因?

go build -a -v

../../../msgq/kafkaAvailMonitor.go:8:2: cannot find package 
  "github.com/Shopify/sarama/tz/breaker" in any of:
  /usr/lib/go-1.6/src/github.com/Shopify/sarama/tz/breaker (from $GOROOT)
  /home/jenkins/go/src/github.com/Shopify/sarama/tz/breaker (from $GOPATH)
  /home/jenkins/vendor-library/src/github.com/Shopify/sarama/tz/breaker
  /home/jenkins/go/src/github.com/Shopify/sarama/tz/breaker
  /home/jenkins/vendor-library/src/github.com/Shopify/sarama/tz/breaker

推荐答案

如果以下不是堆栈跟踪,那是什么?

这是GO正在寻找丢失的包裹的路径列表.

我不知道谁在进口kafkaAvailMonitor or.go

它不是"导入"的,只是您的源代码的一部分并进行了编译.
除非它不能编译,因为它需要github.com/Shopify/sarama/tz/breaker,而这不在GOROOTGOPATH中.

不过,还是要判断一下你的直达套餐上有多少go list would return,看看是否提到了kafkaAvailMonitor.

go list既可以显示您的包直接依赖的包,也可以显示其完整的可传递依赖项集.

% go list -f '{{ .Imports }}' github.com/davecheney/profile
[io/ioutil log os os/signal path/filepath runtime runtime/pprof]
% go list -f '{{ .Deps }}' github.com/davecheney/profile
[bufio bytes errors fmt io io/ioutil log math os os/signal path/filepath reflect run

然后,您可以编写GO LIST脚本以列出all个依赖项.
this bash script for instance,由Noel Cower (nilium)

#!/usr/bin/env bash
# Usage: lsdep [PACKAGE...]
#
# Example (list github.com/foo/bar and package dir deps [the . argument])
# $ lsdep github.com/foo/bar .
#
# By default, this will list dependencies (imports), test imports, and test
# dependencies (imports made by test imports).  You can recurse further by
# setting TESTIMPORTS to an integer greater than one, or to skip test
# dependencies, set TESTIMPORTS to 0 or a negative integer.

: "${TESTIMPORTS:=1}"

lsdep_impl__ () {
    local txtestimps='{{range $v := .TestImports}}{{print . "\n"}}{{end}}'
    local txdeps='{{range $v := .Deps}}{{print . "\n"}}{{end}}'

    {
        go list -f "${txtestimps}${txdeps}" "$@"
        if [[ -n "${TESTIMPORTS}" ]] && [[ "${TESTIMPORTS:-1}" -gt 0 ]]
        then
            go list -f "${txtestimps}" "$@" |
            sort | uniq |
            comm -23 - <(go list std | sort) |
                TESTIMPORTS=$((TESTIMPORTS - 1)) xargs bash -c 'lsdep_impl__ "$@"' "$0"
        fi
    } |
    sort | uniq |
    comm -23 - <(go list std | sort)
}
export -f lsdep_impl__

lsdep_impl__ "$@"

Go相关问答推荐

如何禁用Go SRC包中的VSCode警告?

在不耗尽资源的情况下处理S3文件下载

允许在 struct 中使用复合作为函数参数

如何在出现错误时停止从通道读取?

go aws-lambda 与 terraform 中的 exec 格式错误

从带有嵌套括号的字符串中提取值

命令行参数在 Golang 程序中不正确地接受为参数

Secrets Manager Update Secret - Secret String 额外的 JSON 编码

一个Go module可以和之前的非module模块发布在同一个路径下吗?

xml.Unmarshal 不支持的类型 struct

Golang 创建一个带有处理程序的模拟数据库并使用接口调用数据库

GoLang: gocui 边框 colored颜色

具有两个参数的动态规划:天数和优惠券

helm :将 YAML 转换为 JSON 时出错:yaml:第 xx 行:未找到预期的密钥

Golang - 将 [8] 布尔转换为字节

Gorm 在保存/创建时序列化 struct

将 CSVExport 函数传递给处理程序 Gin

GOLANG 如何使用 http.FileServer 从模板目录加载某个 html 文件

Golang 有类似 C++ 的 decltype 的东西吗?

在 etcd 键值存储中禁用历史记录