modules: how to force version of dependent lib
Asked Answered
P

1

6

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

Pendergast answered 18/12, 2019 at 4:37 Comment(3)
Have you tried running go get the/[email protected]? See Go Wiki: Modules: How to Upgrade and Downgrade DependenciesBoreas
Thanks for suggestion ... And Yes I have ... Sure enough go.mod reads v1.1.0. but go build puts back 1.3.0. I'm beginning to think maybe an env var is wrong b/c what you wrote really should done the trick.Pendergast
Is this an indirect dependency?Tuneful
K
4

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
Kayleigh answered 18/12, 2019 at 5:13 Comment(3)
Why do you have go mod vendor there?Commorancy
@Commorancy if the vendor folder is there, then dependencies inside will be updatedKayleigh
Sure, but it's not obvious whether OP uses vendoring (or more correctly: there are signs they don't)Commorancy

© 2022 - 2024 — McMap. All rights reserved.