go mod vendor 没有更新到最新

标签 go go-modules

我想弄清楚是否可以在没有 go 工具更新我的 go.mod 文件的情况下运行 go mod vendor。

我特别go get package/subpackage@commit 并使用正确的版本提交我的 go.mod

然后我运行 go mod vendor,它会自动更新我刚刚专门设置的包的版本。

我查看此页面无济于事:https://github.com/golang/go/wiki/Modules#how-do-i-use-vendoring-with-modules-is-vendoring-going-away

我需要使用 vendor,因为我运行了一个脚本来编辑一些 vendored deps。我正在查看以下构建流程:

GO111MODULE=on go get package/subpackge@commit
GO111MODULE=on go mod vendor
./Script/patch_vendors.sh --write
GO111MODULE=off go build

我的另一个选择是在 go mod vendor 将其下载到的任何地方修改复制的源,但是 不确定如何处理。

提前致谢

最佳答案

根据 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 […].

go mod vendor 命令复制你的包及其测试的所有传递导入,因此它会自动更新 go.mod 文件以确保所有存在导入的包。

所以这里的问题很可能是您为 package/subpackage 选择的 commit 未能提供出现在程序的传递导入中的某些包。如果这是正确的,您应该会发现 go list allgo test allgo mod tidy 都对您的模块进行了相同的编辑要求。

关于go mod vendor 没有更新到最新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55467083/

相关文章:

google-app-engine - gorilla mux 子域

模板中的 Golang 模板全局点,其值来自范围

pointers - [Golang]指针类型、指针类型和结构体类型调用方法有什么不同?

mysql - 如何为 Golang 格式化 MySql CREATE USER 语句

git - Go mod 用私有(private) fork 替换依赖

go - 替换go.sum中的字符串

go - 如何找到 Go 模块源缓存?

go - 通过drone.io提交代码构建应用时,如何在代码中提供所需的go模块?

Golang gqlgen 错误尝试将模型导入resolver.go

http - 你如何在 Golang 中使用摘要身份验证进行 HTTP POST?