简体   繁体   中英

modules: how to force version of dependent lib

Overall go modules works just like the docs say. But, in one case, a dependent lib's latest tag is v1.3.0 which go mod tidy finds. However I need v1.1.0. No matter what I do (hand edit go.mod, go get -u) 'go build' merely reverts the version right back to v1.3.0 which breaks the build. Indeed, the whole point of modules is setting the dependencies: so how? Go get should set it permanently but it doesn't stay set. Using go1.13.5

No matter what I do (hand edit go.mod, go get -u) ...

After you modify the version of the dependency in the go.mod file, then what you need to do is perform go mod tidy command (from your explanation I assume you haven't done it).

Example:

# modify the dependency version on go.mod, then
go mod tidy

If you use vendoring then you also need to run the go mod vendor command to update the downloaded dependencies inside vendor/ folder.

# modify the dependency version on go.mod, then
go mod tidy
go mod vendor

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM