duanna5749
duanna5749
2019-04-13 04:55

收到错误:构建Go项目时,“ build flag -mod = vendor仅在使用模块时有效”

According to this document I need to add -mod=vendor to my build command to make use of my local vendor folder:

By default, go commands like go build ignore the vendor directory when in module mode. The -mod=vendor flag (e.g., go build -mod=vendor) instructs the go commands to use the main module's top-level vendor directory to satisfy dependencies.

When I run this command:

go build -mod=vendor -a -ldflags "-s -w -X github.com/my-api/pkg/config.Version=169.3988801" -o bin/my-api

I get this error:

build flag -mod=vendor only valid when using modules

Locally the command works as expected, the error only occurs on the build server.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doudou_3636 doudou_3636 2年前

    I think the key part of the help you are showing is when in module mode. This will only happen when you are working on code outside of GOPATH or if you have set the GO111MODULE=on environment variable so I think you have this set in your local environment but not the build server.

    More information about enabling module support is here:

    https://golang.org/cmd/go/#hdr-Preliminary_module_support

    点赞 评论 复制链接分享

为你推荐