简体   繁体   English

使用dep时强制特定版本的依赖项

[英]Force a specific version for a dependency when using dep

I am using dep to manage the dependencies of a Go tool I'm writing. 我正在使用dep来管理我正在编写的Go工具的依赖项。

This tool uses https://github.com/desertbit/grumble as an dependency. 此工具使用https://github.com/desertbit/grumble作为依赖项。 This in turn uses https://github.com/chzyer/readline as a dependency. 这反过来使用https://github.com/chzyer/readline作为依赖。 The problem is that when trying to run my tool I get the following error: vendor/github.com/desertbit/grumble/app.go:295:20: unknown field 'HistorySearchFold' in struct literal of type readline.Config 问题是,当我尝试运行我的工具时,我收到以下错误: vendor/github.com/desertbit/grumble/app.go:295:20: unknown field 'HistorySearchFold' in struct literal of type readline.Config

I know why this is happending. 我知道为什么会这样。 grumble uses the master branch of readline as a dependency. grumble使用readlinemaster分支作为依赖。 In this the field HistorySearchFold is available. 在此,可以使用HistorySearchFold字段。 When using dep init / dep ensure not the master but the 1.4 tag is pulled into the vendor folder. 使用dep init / dep ensure不是master,而是将1.4标签拉入vendor文件夹。

My question therefore is: How can I force dep to pull the master branch instead? 因此我的问题是:我如何强制dep拉取分支呢?

I tried adding the following in my Gopkg.toml file: 我尝试在我的Gopkg.toml文件中添加以下内容:

[[constraint]]
  branch = "master"
  name = "github.com/chzyer/readline"

Sadly this is not working. 可悲的是,这不起作用。 When I check the version pulled into the vendor folder it is still 1.4 . 当我检查拉入供应商文件夹的版本时,它仍然是1.4

If you are trying to control the version of a transient dependency (not one directly used by your package, you should use the [[override]] directive 如果您试图控制瞬态依赖的版本(不是您的包直接使用的版本),您应该使用[[override]]指令

It looks exactly the same as a constraint, but it will constrain dependencies even when not directly inherited by your package. 它看起来与约束完全相同,但即使不直接由包继承,它也会限制依赖关系。

[[override]]
  branch = "master"
  name = "github.com/chzyer/readline"

Note that this is also useful for when the dependency solver finds conflicting dependencies, eg your package P makes use of packages A and B, and both depend on different versions of package X... you can use an override on package X inside of your package P 请注意,这对于依赖项解算器发现冲突依赖项时也很有用,例如,包P使用包A和B,并且两者都依赖于包X的不同版本...您可以在包内使用包X上的覆盖包P

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM