Hello Mihai,

To upgrade your direct dependencies to their latest release (with your 
indirect dependencies using versions selected based on the requirements of 
your direct dependencies), this should work in most cases:

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

Does that work for you?

There is an issue suggesting allowing this to be specified more easily:

    #28424 cmd/go: add 'go get' options to update direct and indirect 
dependencies separately
    https://github.com/golang/go/issues/28424  
  
If interested, you could add a comment there briefly explaining your use 
case, or whatever other comment makes sense.

Regards,
thepudds

On Wednesday, September 4, 2019 at 7:35:58 PM UTC-4, mihaib...@gmail.com 
wrote:
>
> Hello,
>
> 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.
>
> Mihai
>

-- 
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 
https://groups.google.com/d/msgid/golang-nuts/b6882ef2-7f48-4a92-af07-1b96ea190abf%40googlegroups.com.

Reply via email to