I recently added a feature to my Go project which might break other projects that uses it. I decided to bump a major version to this project, "A", by adding a matching git tag 2.0.0
(it was previously 1.xx
). In my other project which requires it, "B", I updated its go.mod
file like so:
module gitlab.mydomain.com/namespace/B
go 1.12
require (
gitlab.mydomain.com/namespace/A v2.0.0
)
As you can see, I specifically mentioned v2.0.0
, but once I run B, the version of A is being overridden with v0.0.0-<timestamp>-<revision>
.
I made sure that the tag exists in the remote.
What am I missing here?
Starting with major version 2
( v2
and beyond), you have to modify the import path, you have to add the major version as a suffix to the import path. You must import the package as:
import "gitlab.mydomain.com/namespace/A/v2"
And this must also appear in go.mod
like:
require gitlab.mydomain.com/namespace/A/v2 v2.0.0
Since major versions represent incompatible changes in Semver, their import path must also differ (the same import path denotes the same dependency). This is the import compatibility rule :
If an old package and a new package have the same import path,
the new package must be backwards compatible with the old package.
Read more about it in Go Modules Wiki: Why must major version numbers appear in import paths?
And also in blog post: The Go Blog: Go Modules: v2 and Beyond
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.