我正在开发一个使用 Glide 的 Go 项目。用于依赖管理。我需要对项目进行更改,还需要对项目使用的几个依赖项进行更改。在分别提交对每个项目的更改之前,我需要一起测试这些更改。
我怎样才能告诉 Glide(或 Go)使用这些项目的本地版本(例如,在 $GOPATH/src/...
中找到)而不是拉下一些东西并将其填充到 vendor
目录)?
举个例子:
github.com/hyperledger/burrow
取决于:github.com/tendermint/tendermint
,这取决于:github.com/tendermint/go-crypto
我需要对所有三个项目进行一些更改。我想通过执行 burrow
项目中的东西来测试更改,但我需要它来执行我的 tendermint
和 go-crypto
的开发版本,我在本地有。
最佳答案
如果你想测试 '$GOPATH/src/...' 下的依赖关系,只需暂时删除项目根目录中的每个 glide 文件(glide.yaml、glide.lock 等...)。 然后,如果您需要再次使用“vendor ”依赖项,则可以放回这些文件。
更新 1
我一直在为我的项目寻找相同的解决方案,然后我发现 glide 文档在 glide.yaml 上为导入指定了一个额外有用的参数。 根据the official documentation :
repo
: If the package name isn't the repo location or this is a private repository it can go here. The package will be checked out from the repo and put where the package name specifies. This allows using forks.
在这种情况下,您只需将代码推送到某个地方(我猜是 GitHub 或 Gitlab 用于您的 $GOPATH/src/github.com/hyperledger/burrow 的私有(private)存储库),然后编辑您的 glide.yaml:
- package: github.com/tendermint/tendermint <-- vendor name dependencies
repo: github.com/myrepo/tendermint <-- your remote fork
version: vx.x.x or your sha commit code
通过这种方式,您可以从官方版本切换到您的 fork 并进行测试。 要返回您的官方版本,只需删除或评论 repo 和版本属性:
- package: github.com/tendermint/tendermint <-- vendor name dependencies
# repo: github.com/myrepo/tendermint <-- your remote fork
# version: vx.x.x or your sha commit code
我现在正在以这种方式测试我的 fork,您无需将导入路径更改为代码,希望这会有所帮助。
更新 2
另一个有用的方法是使用 glide mirror :
Mirrors provide the ability to replace a repo location with another location that's a mirror of the original. This is useful when you want to have a cache for your continuous integration (CI) system or if you want to work on a dependency in a local location.
我猜这是最好的解决方案,例如,在命令行类型上:
$ glide mirror set github.com/tendermint/tendermint file:///User/yourname/Gospace/src/github.com/tendermint/tendermint
这将在您的 GLIDE_HOME 中创建一个 mirror.yaml(如果不存在,则将放在您的 $USER/.glide 文件夹下)。 现在你可以测试你的本地版本(在 GOPATH 下)而不用 fork 你的项目(正如我上面写的)。 完成测试后,只需将其删除:
$ glide mirror remove github.com/tendermint/tendermint
关于go - 如何使用本地版本的 glide 依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44802725/