关于go模块:转到mod供应商,而无需更新到最新版本

go mod vendor without update to latest

我想弄清楚是否可以在不使用go工具更新go.mod文件的情况下运行go mod供应商。

我专门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

我需要使用供应商,因为我运行的脚本可以编辑某些供应商的部门。我正在查看以下构建流程:

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

我的另一种选择是修改复制的源代码,无论供应商将其下载到何处,但是
不知道该如何处理。

提前致谢


根据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都对模块的要求进行了相同的编辑。