I’m trying to debug the following build error in our CI where "A depends on B which can’t build because it depends on C." I’m building my data service which doesn’t directly depend on kafkaAvailMonitor.go which makes this error hard to trace. In other words:
data (what I’m building) depends on (?) which depends on
kafkaAvailMonitor.go
It may seem trivial to fix for a developer they just do "go get whatever" but I can’t do that as part of the release process – I have to find the person that added the dependency and ask them to fix it.
I’m aware that there are tools to visualize the dependency tree and other more sophisticated build systems, but this seems like a pretty basic issue: is there any way I can view the full dependency tree to see what’s causing the build issue?
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
6
Answers
The above answer still doesn't show me a dependency tree so I've taken the time to write a Python script to do what I need - hopefully that helps other people.
The issue with the above solution (the others proposed like go list) is that it only tells me the top level. They don't "traverse the tree." This is the output I get - which doesn't help any more than what go build gives me.
This is what I'm trying to get - I know that auth is broken (top) and that breaker is broken (bottom) from go build but I have no idea what's in between - my script below gives me this output.
My Python script:
It is the list of path where Go is looking for your missing package.
It is not “imported”, just part of your sources and compiled.
Except it cannot compile, because it needs
github.com/Shopify/sarama/tz/breaker
, which is not inGOROOT
orGOPATH
.Still, check what
go list
would return on your direct package, to see ifkafkaAvailMonitor
is mentioned.You can then script go list in order to list all dependencies.
See this bash script for instance, by Noel Cower (
nilium
)When using modules you may be able to get what you need from
go mod graph
.I.e., for the original question, run
go mod graph | grep github.com/Shopify/sarama
then look more closely at each entry on the left-hand side.I just want to mention here that
go mod why
can also help. Anyway you cannot get and display the whole tree. But you can trace back one single branch of a child dependency until its parent root.Example:
That means, you have imported ‘childdep’ finally in ‘anotherrepo.git/mocks’.
can try this https://github.com/vc60er/deptree
The dependency of a Go project is a directional graph. This graph consists of multiple layers, ranging from several to hundreds or thousands. Here is an dependency graph of redis. The cascaded tree can be difficult to understand due to the presence of many duplicated subtrees. To make the layout easier to view, the tree can be flattened via gomoddeps to fit the width of the screen.