#php editor Xiaoxin explains why two versions of the same package are downloaded when using the "go get -u" command. The reason for this problem lies in how go mod works. go mod is a dependency management tool introduced by the Go language in version 1.11. It will automatically download and manage dependency packages based on the project's go.mod file. When we use the "go get -u" command, it checks the dependency package version in the go.mod file and tries to download the latest version. However, version updates of some packages may depend on different versions of other packages, so go mod will download two versions of the package to satisfy the dependency, which is why two versions of the same package will be downloaded.
I use go get -u
to get packages that depend on golang.org/x/[email protected]
. I noticed that it downloads golang.org/x/[email protected]
first and then golang.org/x/[email protected]
.
Then I ran go clean -modcache
and go get golang.org/x/text
and it downloaded golang.org/x/text
v0.4.0
and then go get -u entgo.io/ent
again. Go was not downloaded this time golang.org/x/[email protected]
So, why does go get -u
download both the old version and the latest version when the latest version is not available locally, and why does it not download the old version when the latest version is available locally?
Because this is a two-step process
From a programming perspective, there is no good reason to merge these into the single concern of "getting the latest dependencies".
From go command documentation:
The-u flag instructs get to update modules that provide dependencies for the package named on the command line to use newer minor or patch versions when available.
This means that -u
deals specifically with modules that the package you fetch depends on, not the module of the package you fetched.
Furthermore, it seems that -u
has nothing to do with the Go idiom of treating any change in version v0
as a major version change, so it cannot be easily recommended out of principle -u
. The readme file of golang.org/x/test even says:
Minor versions are considered major until the x/text version reaches 1.0.0. Therefore going from 0.1.0 to 0.2.0 is considered a major version upgrade.
The above is the detailed content of Why does go get download two versions of the same package when using -u. For more information, please follow other related articles on the PHP Chinese website!