Go import tree

539 views
Skip to first unread message

Tong Sun

unread,
Jul 30, 2017, 12:55:05 AM7/30/17
to golang-nuts
Is there any tools out there that can show import tree for Go projects? I.e., the dependency graph that shows who imports what packages. 

During `go build -v` I saw one (3rd party) package that shouldn't be included, and am wondering who is introducing that dependency. 
How can I find out? Thx. 


bojan...@sbgenomics.com

unread,
Jul 30, 2017, 8:09:45 PM7/30/17
to golang-nuts
You can try using https://github.com/kisielk/godepgraph. Its a great tool. In combination with GraphViz it can produce dependency graphs in various formats.

Of course, you can always do something among the lines of go list -f '{{.Deps}}', but I do not believe it will give you graph, only list of dependencies.

Steve Roth

unread,
Jul 30, 2017, 8:15:43 PM7/30/17
to golang-nuts

Dave Cheney

unread,
Jul 30, 2017, 8:50:18 PM7/30/17
to golang-nuts
This feature is enabled on any package you view through godoc.org; just look at the bottom of the page.

roger peppe

unread,
Jul 31, 2017, 9:30:11 AM7/31/17
to Tong Sun, golang-nuts
I've needed to find out this kind of info lots of times in the past.

I wrote a small tool named "showdeps" that includes the capability
to find out why a dependency is present.

You can run "showdeps -why somepackage" to find out why there
is a dependency on somepackage, which prints a line showing
each package involved in the dependency and the packages
that depend on it.

You can also use the "..." wildcard to find out dependencies
on a whole repo; for example "showdeps -why github.com/foo/bar/..."
would print out all dependencies involved in the chain from
the current package to any package below github.com/foo/bar.

With large dependency projects, I find this quite a bit easier than
trying to work out the linkage by inspecting the whole graph.

To get showdeps:


Hope this helps,

  rog.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages