Search code examples
gomodulepackagedependencies

List dependencies for module, not package


If I have this file:

package main
import "github.com/dinedal/textql/storage"

I can list the dependencies using one of these:

go list -deps
go mod graph

However if I have this file instead:

package main
import "github.com/dinedal/textql"

All the dependencies are not listed. For example looking at the mod file, none of the packages under require are listed now. Finally I tried this with an interesting result:

PS C:\> go list -deps github.com/dinedal/textql
go: finding module for package github.com/dinedal/textql
module github.com/dinedal/textql@latest found
(v0.0.0-20200608170856-250cf763f52c), but does not contain package
github.com/dinedal/textql

Solution

  • Based on the comments, I was able to get a list of dependencies for a module like this:

    go mod init deps
    go get github.com/dinedal/textql
    go list -deps github.com/dinedal/textql/...
    

    Also this command can be used for testing, as it clears out of the module cache:

    go clean -modcache