Reputation: 4530
My coworker pushed a tag v3.0.1
before updating go.mod
to have /v3
suffix (https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher). I have updated module path (go.mod
) and all import paths (*.go
) to fix it, tagged as v3.0.2
.
Now the problem is:
go get -v git.example.com/owner/[email protected]
go: finding git.example.com/owner/repo v3.0.2
go: git.example.com/owner/[email protected]: go.mod has post-v0 module path "git.example.com/owner/repo/v3" at revision
d85c4f69ad17
Found this: go build keeps complaining that: go.mod has post-v0 module path
So, I deleted both v3.0.0
and v3.0.1
tags, pointed it to the latest commit, re-pushed but the problem still stand.
I noticed that go.mod
still refered to the old version as an indirect dependency:
require (
git.example.com/owner.repo v0.1.2 // indirect
Even if I changed it to /v3 v3.0.2
it will be restored to v0.1.12
automatically.
Why?
Did I miss something?
Tue Jul 23 05:54:56 +07 2019
rm go.*
go mod init git.example.com/dependent/project
go mod tidy
and go.mod
is updated correctly now:
require (
- git.example.com/owner/repo v0.1.2
+ git.example.com/owner/repo/v3 v3.0.2
but go get -v git.example.com/owner/[email protected]
still returned the error:
go: finding git.example.com/owner/repo v3.0.2
go: git.example.com/owner/[email protected]: go.mod has post-v0 module path "git.example.com/owner/repo/v3" at revision
d85c4f69ad17
(d85c4f69ad17
is the latest commit in master
)
I noticed that there are both v0.1.2
and v3.0.2
in go.sum
:
git.example.com/owner/repo v0.1.2 h1:mCGJEmyrFDTCGkRfUIORpqdrNkSONQ6K+AcTNgxqveY=
git.example.com/owner/repo v0.1.2/go.mod h1:FfUKnyPrARCtAXQZ3BQVJI7h2eJ0UpQBMLg4bNs4Kdc=
git.example.com/owner/repo/v3 v3.0.2 h1:mJtDKLeiP8vMRSZo08i/k/KDbIoZTlKW2aWu7DUBvMM=
git.example.com/owner/repo/v3 v3.0.2/go.mod h1:64LE0ts0Lk9InIQyhPYGmnxs6LZIl6H4Iorl1EXfqxo=
Upvotes: 6
Views: 1942
Reputation: 810
I may have had a similiar issue where I updated a module to use the /v2 import path but go getting the module always returned an error about invalid go.mod
The solution was to go get -u github.com/<me>/<pkg>/v2
Upvotes: 0
Reputation: 4530
Please pay attention to my go get
command:
go get -v git.example.com/owner/[email protected]
It should be:
go get -v git.example.com/owner/repo/[email protected]
Upvotes: 6
Reputation: 5284
Expanding on the answer from @quanta...
You are doing:
go get -v git.example.com/owner/[email protected]
Because it is a v3 module, the go get
command should include a /v3
before the @
:
go get -v git.example.com/owner/repo/[email protected]
Once a v3.x.y package is a module with its own go.mod, then whenenver you are operating with modules enabled, you pretty much always include the /v3
whenever you reference the v3.x.y module, including in:
go get
on the command line.go
code for the consumerrequire
statements in a consumer's go.modreplace
or exclude
statements in a consumer's go.modmodule
line of the v3 module's go.mod file.go
code inside the v3 module importing other packages in the v3 moduleOne way to think about it is that the module's name is now effectively git.example.com/owner/repo/v3
, where its name includes the trailing /v3
.
If you are a consumer of a vN
module and need to update your import paths in your .go
files to include the vN
, then
github.com/marwan-at-work/mod is a commonly used tool from the community that automates adding the /vN
in all the required spots. Separately, it also automates placing the /vN
in all the required spots if you are a module author for a v2+ module.
From the "Semantic Import Versioning" section of the Go modules wiki:
If the module is version v2 or higher, the major version of the module must be included as a /vN at the end of the module paths used in go.mod files (e.g.,
module github.com/my/mod/v2
,require github.com/my/mod/v2 v2.0.0
) and in the package import path (e.g.,import "github.com/my/mod/v2/mypkg"
).
Upvotes: 1
Reputation: 1924
for example you can replace repository with this hack: https://github.com/golang/go/wiki/Modules
require {
...
}
replace git.example.com/owner.repo v0.1.2 => git.example.com/owner.repo v3.0.2
or you can use go get
at the commit hash you want:
go get git.example.com/owner.repo@af044c0995fe
go get
will correctly update the dependency files (go.mod, go.sum).
For more information: https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies
or for last example you should clean cache
go.mod
and go.sum
go cache clean
go mod vendor
Upvotes: 0