go - 如何防止 `go build`更新模块的最新版本

标签 go go-build

我正在一个大型项目中使用名为“yaegi ”的开源项目。

我需要使用旧版本的“yaegi”:v.0.8.11,因此我修改了go.mod文件并替换为:
github.com/traefik/yaegi v0.9.2//间接github.com/containous/yaegi v0.8.11
但是当我构建项目时,它开始更新所有模块并将其替换回最新版本:

root@ubuntu:~/myproj1# go build main.go
go: finding module for package github.com/traefik/yaegi/stdlib/unsafe
go: finding module for package github.com/traefik/yaegi/stdlib
go: finding module for package github.com/traefik/yaegi/interp
go: found github.com/traefik/yaegi/interp in github.com/traefik/yaegi v0.9.2

如何防止它并使用旧版本 v.0.8.11 保留它?
read根据https://tip.golang.org/cmd/go/#hdr-Maintaining_module_requirements :

The go command itself automatically updates the go.mod file to maintain a standard formatting and the accuracy of require statements.

Any go command that finds an unfamiliar import will look up the module containing that import and add the latest version of that module to go.mod automatically. […]

Any go command can determine that a module requirement is missing and must be added […].

也许有办法绕过它?

最佳答案

//indirectgo.mod意味着您要导入的其他模块中至少有一个依赖于该版本的模块,因此 go build将自动更新该模块,无论您如何更改 go.mod 中的该行。在您的情况下,如果您不想使用 yaegi v0.9.2的模块您必须首先从项目中删除依赖于该模块的其他依赖项,然后修复您的 go.mod使您的项目需要 yaegi v0.8.11 。您可以删除它们或使它们需要早期版本的 yaegi通过使用旧版本或编辑源代码。另外,不要编辑 go.mod直接,我会运行类似 go get -v github.com/containous/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c352d292b250c7c6274627d7d" rel="noreferrer noopener nofollow">[email protected]</a> 的命令 checkout 模块的特定版本。

关于go - 如何防止 `go build`更新模块的最新版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64352451/

相关文章:

regex - 在括号外用逗号标记

go - 如何将 gota 数据框写入 csv?

macos - $GOPATH 已设置但 go install 不起作用

go - 如何使用 Go 模块修复 Go build error "can' t load package"?

Golang安装

go - 如何在父子顺序中构造yaml文件?

GO:查找/扫描结构/函数

pointers - 不使用 reflrect 打印类型并创建新对象

Golang 条件编译

go build 不会将本地更改编译到 main