我正在一个大型项目中使用名为“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 thego.mod
file to maintain a standard formatting and the accuracy ofrequire
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 […].
也许有办法绕过它?
最佳答案
//indirect
在go.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/