问题描述
在dep
中,您可以选择覆盖依赖项,并使其指向其他存储库,例如,在以下 https://github.com/kubermatic/glog-logrus 库需要在Gopkg.toml文件中添加以下几行:
In dep
you have the option to override a dependency and have it point to a different repo for example in the following https://github.com/kubermatic/glog-logrus library one needs to add the following lines to the Gopkg.toml file:
[[override]]
name = "github.com/golang/glog"
source = "github.com/kubermatic/glog-logrus"
然后在代码库中输入import "github.com/golang/glog
.但是,在go模块中,我看不到这样的选择吗?这使我认为唯一的解决方案是将导入更改为github.com/kubermatic/glog-logrus
.
Then in the codebase you import "github.com/golang/glog
. However, in go modules I don't see such an option? which leads me to think the only solution is to change the import to github.com/kubermatic/glog-logrus
.
谢谢!
推荐答案
这是replace
指令的作用.
引用Wiki 转到1.11版模块:什么时候应该使用replace指令?
因此将其添加到主模块的go.mod
文件中:
So add this to the go.mod
file of your main module:
replace (
github.com/golang/glog => github.com/kubermatic/glog-logrus v0.0.0
)
您还可以指示go
工具为您进行此修改:
You can also instruct the go
tool to make this edit for you:
go mod edit -replace github.com/golang/glog=github.com/kubermatic/[email protected]
(使用您感兴趣的版本.)
(Use the version you're interested in.)
此后,当您导入github.com/golang/glog
时,将使用github.com/kubermatic/glog-logrus
(无需更改导入语句).
After this when you import github.com/golang/glog
, github.com/kubermatic/glog-logrus
will be used (without having to change import statements).
这篇关于如何覆盖go模块中的依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!