dimus
dimus

Reputation: 9372

How to determine which module/s use an indirect dependency?

In Go 1.17 go.mod has two sections, 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 particuar indirect dependency what module or modules use it?

Upvotes: 32

Views: 20680

Answers (1)

bcmills
bcmills

Reputation: 5187

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.)

Upvotes: 46

Related Questions