如何仅使用供应商依赖项运行go命令?

huangapple go评论161阅读模式
英文:

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进行供应商管理。

最推荐的工作流程:

  1. glide.yaml中保持实际的依赖列表。
  2. glide.yaml中进行任何更改后运行glide up。它将安装所有依赖项到vendor目录,并生成带有固定包版本的glide.lock。将glide.lock提交到版本控制系统(VCS)。不要手动更改glide.lock
  3. 不要vendor目录提交到VCS。
  4. 在CI或构建服务器上运行glide install,通过glide.lock将依赖项安装到vendor目录。
  5. 构建。

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:

  1. Keep actual list of dependencies in glide.yaml.
  2. Run glide up after any changes in glide.yaml. It will install all dependencies to vendor directory and generate glide.lock with fixed package versions. Commit glide.lock to VCS. Do not change manually glide.lock.
  3. Do not commit vendor directory to VCS.
  4. Run glide install on your CI or build server to install dependencies by glide.lock to vendor.
  5. Build.

A migration from godep to glide may be done easily, because glide has a command to migrate Godeps.json to glide.yaml.

huangapple
  • 本文由 发表于 2016年7月19日 23:57:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/38463367.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定