How do I update all direct and indirect dependencies in go.mod

783 views
Skip to first unread message

Francis Chuang

unread,
Feb 26, 2019, 7:43:18 PM2/26/19
to golang-nuts
I have dependencies (direct and some indirect) listed in my go.mod file. This was initially populated using `go ./...` after creating the go.mod using `go mod init`.

I now want to upgrade the dependencies and the indirect dependencies in the go.mod file to their latest versions.

If I run `go get -u`, it pulls in the latest versions of the dependencies as well as all the dependencies for running their tests on all platforms. In effect, my go.mod file has more then tripled in size. 

Is there any way to update my direct (and some required indirect) dependencies required just to build my project in go.mod?

thepud...@gmail.com

unread,
Feb 26, 2019, 8:06:13 PM2/26/19
to golang-nuts
Hi Francis,

To ask that your direct dependencies be upgraded to their latest available versions, you can do the following in Go 1.11 or 1.12:

  go get $(go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all)

Your indirect dependencies will be updated as needed according to the requirements of your direct dependencies.

There is a proposal to make that easier here, along with some related discussion:

https://github.com/golang/go/issues/28424

Regards,
thepudds

Francis Chuang

unread,
Feb 26, 2019, 8:27:50 PM2/26/19
to golang-nuts
Thanks for the tip! I've subscribed to your github issue as well. Hopefully, it will be implemented in 1.13, as I feel that this is a pretty common usecase.
Reply all
Reply to author
Forward
0 new messages