I am looking for a way to regularly update my Go module's direct 
dependencies. Without specifying indirect dependencies myself: let my 
direct dependencies specify what they need in their own go.mod.

After reading relevant documentation, I could only come up with this 
partial workaround:

go list -m -u -f '{{if and (and (not .Indirect) (not .Main)) 
.Update}}{{.Path}}@{{.Update.Version}}{{end}}' all | xargs 
--no-run-if-empty go get

Suspecting this scenario is common and useful, I have prepared a minimal 
concrete example below (each module is a repository under github.com/MihaiB 
for now).
"X → Y" means "module X depends directly on module Y".
I have the following Go modules:

goMain → goA → goB
goMain's tests → goT

All modules have published versions v1.1.0, v1.2.0 and v2.0.0 (except 
goMain which has no version tags). All dependency arrows above (go.mod 
entries) specify v1.1.0, so all can be updated.

goMain's .go files are in a sub/dir/ to make sure the commands I type 
inspect all packages inside the module, but this isn't mandatory: I can 
also repeat a command in each package's directory if needed.

In goMain:
$ cat go.mod 
module github.com/MihaiB/goMain

go 1.13

require (
github.com/MihaiB/goA v1.1.0
github.com/MihaiB/goT v1.1.0

1) How to find out if goA or goT have a newer v1 version, and update to it?
My 'go list … | xargs …' workaround above does this by listing the direct 
dependencies and passing them to 'go get'.
Would it make sense to support this functionality via a shorter command?
I cannot use 'go get -u -t -d ./...' here because that brings in the 
indirect dependency 'goB' into my go.mod.

2) How to find out if goA or goT have a newer major version (v2 or later)?
I know that v2 and later have a different import path (ending in "/v2"), so 
different major versions are different packages and they can be used 
together in my module.
But I would like a command which tells me if some of my direct dependencies 
have a newer major version, otherwise I would have to check each dependency 
by hand to find out.


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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 

Reply via email to