In Go, go.mod file has two set of dependencies (became two separate sections in Go 1.17), direct dependencies and indirect dependencies.
However, there is no indication how indirect dependencies are related to direct dependencies.
How can I find out for a particular indirect dependency what module or modules use it?
go mod why -m $MODULE
will give you one (arbitrarily-chosen) chain of imports from a package in your module to a package in $MODULE
. However, it does not natively report all such paths.
go list -json all
does expose enough information to identify those paths, but it does not provide an easy way to present import chains for human consumption. However, some third-party tools (such as goda
and gomod
) can transform or query the output from go list
with more structure. (See their documentation for query syntax and examples.)