go - 在 golang 中强制传递依赖版本

标签 go dependencies

我有一个关于 golang 依赖项的问题。
我的应用程序定义了一个 go.mod,如下所示:

module my.host.com/myapp

require (
    ext1.com/module1 v0.0.1
)

go 1.14
ext1.com/module1 依赖于 ext2.com/module2 v0.0.2,而后者又依赖于 ext3.com/module3 v0.0.3
安全扫描检测到 ext3.com/module3 v0.0.3 不安全,必须更新到 v0.0.4。
有没有办法“强制” myapp 只获取 repo3.com/module3 v0.0.4,覆盖 module2 v0.0.2 go.mod 中定义的指令?
假设 ext1.com/module1 v0.0.1 已经是最新版本,所以升级它不起作用。
“排除 ext3.com/module3 v0.0.3”也不起作用:构建成功(golang 1.17.2),但存在运行时错误。
“替换”会起作用吗?假设 ext2 v0.0.3 依赖于安全的 ext3 v0.0.4,我的意思是:
module my.host.com/myapp

require (
    ext1.com/module1 v0.0.1
)

replace ext2.com/module2 v0.0.2 => ext2.com/module2 v0.0.3

go 1.14
提前致谢!

最佳答案

运行 go get -u ext3.com/module3@v0.0.4 .
这会将模块升级到 至少 v0.0.4鉴于依赖 main -> B -> C , 当 main需要更高版本的 CB 所要求的要多,选择高版本,// indirect .
看到这个 https://go.dev/ref/mod#go-mod-file-require

If the go directive specifies go 1.16 or lower, the go command adds an indirect requirement when the selected version of a module is higher than what is already implied (transitively) by the main module’s other dependencies. That may occur because of an explicit upgrade (go get -u ./...)


我引用这部分是因为你的 go.mod 有 go 1.14

关于go - 在 golang 中强制传递依赖版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70100325/

相关文章:

json - 戈朗 : Parsing benchmarking between message pack and JSON

go - 有没有更简单的方法来附加一片结构?

奇怪的行为 - 变量没有正确递增

gcc - 关于 Makefile 的问题 - 什么是 "$+"& .c 文件/依赖项在哪里调用?

android - 最新 Android Studio 更新 3.3.2 后 Unresolved DataBinding 依赖关系

reference - Visual Studio 2017引用与依存关系

java - 如何将开源库安装到Eclipse?

go - 如何通过Web程序集访问Go中的JS对象

go - 在 Go 中打开多个 keep-alive 到服务器

java - 未能应用插件 [class 'io.spring.gradle.dependencymanagement.DependencyManagementPlugin']?