在 golang 中强制传递依赖版本
force a transitive dependency version in golang
我对 golang 中的依赖项有疑问。
我的应用程序这样定义 go.mod:
module my.host.com/myapp
require (
ext1.com/module1 v0.0.1
)
go 1.14
依赖关系为:
- ext1.com/module1 v0.0.1 依赖于 ext3.com/module3 v0.0.3
安全扫描检测到 ext3。com/module3 v0.0.3 不安全,必须更新到 v0.0.4。
有没有办法“强制”myapp 只获取 module3 v0.0.4,覆盖 module1 v0.0.1[=35= 中定义的指令] go.mod?
- 假设ext1.com/module1 v0.0.1已经是最新版本了,升级不行。
“替代”有用吗?
module my.host.com/myapp
require (
ext1.com/module1 v0.0.1
)
replace ext3.com/module3 v0.0.3 => ext3.com/module3 v0.0.4
go 1.14
提前致谢!
运行 go get -u ext3.com/module3@v0.0.4
.
这会将模块升级到 至少 v0.0.4
给定依赖关系main -> B -> C
,当main
需要比B
更高版本的C
时,选择更高版本,[=16] =].
看到这个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
我对 golang 中的依赖项有疑问。 我的应用程序这样定义 go.mod:
module my.host.com/myapp
require (
ext1.com/module1 v0.0.1
)
go 1.14
依赖关系为:
- ext1.com/module1 v0.0.1 依赖于 ext3.com/module3 v0.0.3
安全扫描检测到 ext3。com/module3 v0.0.3 不安全,必须更新到 v0.0.4。
有没有办法“强制”myapp 只获取 module3 v0.0.4,覆盖 module1 v0.0.1[=35= 中定义的指令] go.mod?
- 假设ext1.com/module1 v0.0.1已经是最新版本了,升级不行。
“替代”有用吗?
module my.host.com/myapp
require (
ext1.com/module1 v0.0.1
)
replace ext3.com/module3 v0.0.3 => ext3.com/module3 v0.0.4
go 1.14
提前致谢!
运行 go get -u ext3.com/module3@v0.0.4
.
这会将模块升级到 至少 v0.0.4
给定依赖关系main -> B -> C
,当main
需要比B
更高版本的C
时,选择更高版本,[=16] =].
看到这个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