英文:
How to run go command using only vendor dependencies?
问题
我遇到了一个问题,我在本地安装了依赖项,它可以正常工作,但是当我推送到持续集成服务器时,它就会出错,因为我忘记了运行godep save ./...来保存依赖项。
我如何在运行go命令时要求使用vendor导入?
编辑:
我正在使用go1.6。如果第三方依赖项无法解析到vendor,我希望命令失败。换句话说,在测试期间是否有一种停止解析$GOPATH中的依赖项的方法?
我不能更改环境变量,因为那样的话我的项目模块就无法解析。我如何强制使用vendor依赖项?
英文:
I keep running into the issue where I install dependencies locally, it works fine, I push to continuous integration server, and then it breaks because I forgot to godep save ./... the dependency.
How can I run the go command but require vendor imports?
Edit:
I'm using go1.6. I want the command to fail if a 3rd-party dependency does not resolve to vendor. In other words, is there a way to stop resolving dependencies in $GOPATH during tests?
I can't change the environment variable because then none of my project modules can be resolved. How can I force vendor dependencies?
答案1
得分: 1
无法阻止构建器扫描$GOPATH以查找包。看起来,您使用的依赖管理流程不太好。我建议您使用glide进行供应商管理。
最推荐的工作流程:
- 在
glide.yaml中保持实际的依赖列表。 - 在
glide.yaml中进行任何更改后运行glide up。它将安装所有依赖项到vendor目录,并生成带有固定包版本的glide.lock。将glide.lock提交到版本控制系统(VCS)。不要手动更改glide.lock。 - 不要将
vendor目录提交到VCS。 - 在CI或构建服务器上运行
glide install,通过glide.lock将依赖项安装到vendor目录。 - 构建。
从godep迁移到glide可能很容易,因为glide有一个命令可以将Godeps.json迁移到glide.yaml。
英文:
There is no way to prevent builder to scan $GOPATH for packages. It seems, that you use not really good flow for manage dependencies. I recommend you to use glide for a vendoring.
Most recommended workflow:
- Keep actual list of dependencies in
glide.yaml. - Run
glide upafter any changes inglide.yaml. It will install all dependencies tovendordirectory and generateglide.lockwith fixed package versions. Commitglide.lockto VCS. Do not change manuallyglide.lock. - Do not commit
vendordirectory to VCS. - Run
glide installon your CI or build server to install dependencies byglide.locktovendor. - Build.
A migration from godep to glide may be done easily, because glide has a command to migrate Godeps.json to glide.yaml.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论