【发布时间】:2018-12-29 02:07:58
【问题描述】:
当我运行以下命令时:- go build -o app 我收到以下错误(对于多个依赖项):main.go:21:2: cannot find package "github.com/gorilla/mux" in any of:
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/go/src/github.com/gorilla/mux (from $GOPATH)
/codebuild/output/src324986171/src/github.com/gorilla/mux
意味着代码构建失败。知道如何解决这个问题,或者一般来说问题出在哪里? 感谢您的帮助。
编辑:
将go get ./... 添加到构建后,我的所有本地包都收到以下错误:# cd .; git clone https://github.com/aristotle/dbhelper /go/src/github.com/aristotle/dbhelper
Cloning into '/go/src/github.com/aristotle/dbhelper'...
我的 buildspec.yml 看起来像这样:
version: 0.2
phases:
install:
commands:
- echo CODEBUILD_SRC_DIR - $CODEBUILD_SRC_DIR
- echo GOPATH - $GOPATH
- echo GOROOT - $GOROOT
build:
commands:
- echo Build started on `date`
- echo Getting packages
- go get ./...
- echo Compiling the Go code...
- go build -o app main.go
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- app
【问题讨论】:
-
看起来您缺少依赖项
gorilla/mux... 有没有机会在构建之前运行go get ./...之类的东西? -
是的,我可以,但是当你有很多依赖项时,这不是有点乏味吗?它在我的本地机器上也能正常工作。
-
@user1990524 您的本地计算机很可能已经下载了您第一次添加它们时的所有这些依赖项。你试过silverfighter的建议吗?
-
是的,但我得到了新的错误。
-
现在我没有看到具体的错误。
go get从 github 克隆源代码应该没问题。在一切都是本地的之后,它应该可以构建了。所以不要忘记之后执行go build。而且您不想缓存包,以便管道在每次构建时下载它们。
标签: amazon-web-services go aws-codepipeline aws-codecommit