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

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?

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.