"go get -t ./..."、Travis CI,并安装所有 go 依赖项

"go get -t ./...", Travis CI, and installing all go dependencies

在此处的文档中:https://docs.travis-ci.com/user/languages/go#Dependency-Management

这是安装依赖的步骤:

if go version is greater than or equal to 1.2

go get -t ./...

我的项目是这样的:

root
---- src
  ---- github.com
  ---- myProject
---- pkg

GOPATH 设置为 root

但我收到此错误:

package github.com/aws/aws-lambda-go/lambda: home/travis/build/path/to/package exists but home/travis/build/path/to/package.git does not - stale checkout?

如何像 nodejs 中的 npm install 一样一次性安装所有依赖项?

How do I get all the dependencies to install at once?

这就是 go get 所做的...看起来您的情况可能配置错误或损坏。您可以先尝试一些事情。

  • go get 安装到 $GOPATH 环境变量的第一个路径。确认它已设置为您想要的(通常以名为 go 的目录结尾的路径;将创建子目录 srcpkg 等)。

  • 如果您要使用 ./...,请确保您从正确的目录调用 go get

  • 检查以确保 git 根位于正确的位置

  • 尝试使用非通配符 name/path/address 作为您要获取的包,而不是 ./...

  • 尝试在没有 -t 标志的情况下调用 go get

如果 none 有效,您可以通过删除目录 (home/travis/build/path/to/package) 并重试来解决问题——确保您没有删除任何您使用过的代码上,或 git repository/files,除非它在某处备份。

根据Go tools documentation,你应该只需要调用

go get [packages]

安装指定的包及其依赖项:

Get downloads the packages named by the import paths, along with their dependencies. It then installs the named packages, like 'go install'.

... 省略号是一个可以扩展以匹配任何字符串的通配符。请参阅 Description of Package Lists 部分:

An import path is a pattern if it includes one or more "..." wildcards, each of which can match any string, including the empty string and strings containing slashes. Such a pattern expands to all package directories found in the GOPATH trees with names matching the patterns.

./ 表示 "here":因此,如果您要使用 ./...

,请确保您来自正确的目录 运行

-t 标志用于下载构建测试所需的包:

The -t flag instructs get to also download the packages required to build the tests for the specified packages.

您看到的错误与 git 有关。有时原因不明,但通常可以通过删除目录并重新开始来修复(例如,参见 "Error to install golint" or

(您可能还会发现 this blog post on configuring travis-ci for Go 有帮助。)