我想弄清楚是否可以在没有 go 工具更新我的 go.mod 文件的情况下运行 go mod vendor。
我特别go get package/subpackage@commit
并使用正确的版本提交我的 go.mod
。
然后我运行 go mod vendor
,它会自动更新我刚刚专门设置的包的版本。
我需要使用 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 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 […].
go mod vendor
命令复制你的包及其测试的所有传递导入,因此它会自动更新 go.mod
文件以确保所有存在导入的包。
所以这里的问题很可能是您为 package/subpackage
选择的 commit
未能提供出现在程序的传递导入中的某些包。如果这是正确的,您应该会发现 go list all
、go test all
和 go mod tidy
都对您的模块进行了相同的编辑要求。
关于go mod vendor 没有更新到最新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55467083/