英文:
How to manage building golang projects on travis-ci
问题
我正在开发一个使用TravisCI的Golang项目。作为依赖工具,我使用了Godeps。
在通过git push运行测试之后,出现了以下错误:
# command-line-arguments
cmd/proj/main_test.go:6:2: 找不到包
"command-line-/vendor/github.com/xxxxx/xxxxx/abc",在以下任何位置都找不到:
/home/travis/.gimme/versions/go1.6.linux.amd64/src/command-line-/vendor/github.com/xxxxx/xxxxx/xxx
为什么找不到这个包?
根据构建日志,似乎通过go get命令可以正常工作。
我的travis.yml文件如下:
language: go
sudo: false
go:
- 1.6
- tip
services:
- redis-server
env:
global:
- secure: "xxxxx"
script:
- go fmt ./...
- go vet $(go list ./... | grep -v /vendor/)
- go test -v cmd/xxxx/*.go -xxxx ${XXXXX}
before_install:
- go get github.com/tools/godep
branches:
only:
- master
go版本的tip是可以的。但是1.6或1.5版本无法正常运行。
我该如何处理这种情况?
英文:
I'm developing Golang project and using TravisCI. As dependency tool, Godeps is used.
After running test by git push, something error was happened as below.
# command-line-arguments
cmd/proj/main_test.go:6:2: cannot find package
"command-line-/vendor/github.com/xxxxx/xxxxx/abc" in any of:
/home/travis/.gimme/versions/go1.6.linux.amd64/src/command-line-/vendor/github.com/xxxxx/xxxxx/xxx
Why it can't find package?
As build log, it seems to work well by go get command.
My travis.yml is here.
language: go
sudo: false
go:
- 1.6
- tip
services:
- redis-server
env:
global:
- secure: "xxxxx"
script:
- go fmt ./...
- go vet $(go list ./... | grep -v /vendor/)
- go test -v cmd/xxxx/*.go -xxxx ${XXXXX}
before_install:
- go get github.com/tools/godep
branches:
only:
- master
tip of go version is OK.
But 1.6 or 1.5 version can't run well.
How can I manage that situation?
答案1
得分: 1
Go 1.6对依赖管理的方式与Go 1.5和之前的版本不同。
1.6引入了/vendor
文件夹。每当你导入一个依赖项时,如果库存在/vendor
中,那么该库将被加载。
这个行为在1.5版本中引入,但在那个版本中它是实验性的。这意味着你需要使用GO15VENDOREXPERIMENT=1
环境变量来启用它。
如果你只需要支持1.5和1.6版本,那么在构建1.5项目时,只需将该变量添加到Travis中即可。
如果你需要扩展对1.5之前版本的支持,那么就会稍微复杂一些。
英文:
The way Go 1.6 manages dependencies is different than Go 1.5 and previous versions.
1.6 introduces the /vendor
folder. Whenever you import a dependency, if the library exists in /vendor
, then the library is loaded.
The behavior was introduced in 1.5, but in that version it was experimental. It means that you need to enable it using the GO15VENDOREXPERIMENT=1
environment variable.
If you only need to provide support for 1.5 and 1.6, then simply add the variable to Travis when building 1.5 projects.
If you need to extend support also for versions before 1.5, then it's a little bit more complicated.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论