Go modules pulls old version of a package
Asked Answered
L

6

9

I'm trying to add a new package to my project with go modules. This package is using github.com/docker/docker/client and works fine outside of the project. When I run go mod vendor it pulls docker client package of version v1.13.1 which does not have some of the methods I am using in my code, but in go modules it is tagged as latest. How do I make go mod use the truly latest version of a package?

Lapp answered 30/8, 2019 at 8:4 Comment(0)
P
10

Go Wiki: Modules:

When needed, more specific versions of dependencies can be chosen with commands such as go get [email protected], go get foo@master, go get foo@e3702bed2, or by editing go.mod directly.

If you need the latest commit on the master branch, use

go get github.com/docker/docker/client@master
Phil answered 30/8, 2019 at 8:12 Comment(1)
Using the ...@master at the end is what makes it work!Howe
S
8

This was driving me insane, too: Downloading the "master" or "latest" tag would often download versions one or two commits before HEAD. I found the answer here:

The go command defaults to downloading modules from the public Go module mirror at proxy.golang.org. It also defaults to validating downloaded modules, regardless of source, against the public Go checksum database at sum.golang.org. These defaults work well for publicly available source code.

And apparently there is some caching going on; if you wait a while it usually starts to work, alternatively it helps to temporarily set the version to a specific commit.

To fix it, I set GOPRIVATE=github.com/myuser.

Stroll answered 1/8, 2020 at 16:32 Comment(2)
I was also going insane and you bloody found it well done. Super conflict with the official docs all over the place saying: In this section, "latest" is the latest version with a semver tag, or the latest known commit if there are no semver tags. Prerelease tags are not selected as "latest" unless there are no other semver tags on the repository (details). - github.com/golang/go/wiki/…Panslavism
From the release notes golang.org/doc/go1.13: go env -w GOPROXY=direct to disable this braindead behaviour. Thank you - I was going insane as well.Logger
E
3

In order to get the latest un-tagged version, you need to specify the commit tag you want to have when doing go get

go get github.com/docker/docker/client@[commit-hash]
Ephesian answered 30/8, 2019 at 8:9 Comment(0)
T
1

Would recommend using a specific version (preferred tagged version, if not latest pseudo version instead of master). Having dependency versions locked down in the go.mod file ensures repeatability.

The latest version available in one of the go proxies is https://search.gocenter.io/github.com~2Fdocker~2Fdocker/info?version=v1.14.0-0.20190511020111-3998dffb806f

Tahitian answered 30/8, 2019 at 13:22 Comment(1)
go get github.com/docker/[email protected] instead of go get github.com/docker/docker/[email protected]Tahitian
V
0

Spent the last 20 hours trying to fix a similar problem, in my case, the following steps solved the problem:

  1. delete $GOPATH/pkg/sumdb
  2. delete the go.mod and go.sum files
  3. recreate the module: go mod init name
  4. go test ./...
Virulent answered 7/9, 2020 at 17:59 Comment(0)
H
0

My circumstances don't align perfectly with the original question, but I feel it may be worth mentioning to help others in situations similar to mine:

Context

  • Was working with private modules, i.e., a Go module hosted from private git repository.
    • Access to the private repo was not an issue.
  • Would make and push changes to the private module.
  • A program that imported the private module would consistently pull an old version when running go get, even after running:
go clean -modcache
rm go.sum
go get
go mod tidy

Root Cause: I'm an Idiot

  • I had forgotten that Go uses VCS tagging with versioning.
  • Failed to update the tag to match the current commit.

The Fix

  • The version wasn't ready to be bumped (learning, here), so, in the private module, I ran the following command to align the version with the current commit:
    • Note: This assumes that all repo content has been staged/committed/pushed.

In the private module repo

git tag -d v0.0.0
git push --delete v0.0.0
git tag v0.0.0
git push origin v0.0.0

In the repo that was importing the private repo

go clean -modcache
rm go.sum
go get
go mod tidy
Hertzog answered 2/12, 2022 at 12:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.