首页 > 解决方案 > GoLand 没有检测到 $GOPATH/pkg/mod 下的供应商包?

问题描述

Goland 未检测到从 github.com 导入的模块。这些模块在 $GOPATH/pkg/mod 目录中可用,但导入没有被解析。供应商目录也下载了所有包。

Goland 版本:2019.3.3 Go 版本:Go 1.13.7

在首选项下:

 - GOROOT is set to /usr/local/go
 - Global GOPATH is set to /Users/xyz/go
 - Go module integration is enabled
 - Enable vendoring support is enabled. 
 - dep integration is not enabled. 

项目结构:

- project-name
  - bin
  - build
  - cmd
     - serviced
        - main.go
  - internal 
    - config
      - config.go
  - vendor
    - github.com
      - .....
  - go.mod 

- External Libraries
  - GO SDK 1.13.7

值得一提的是,Goland 并没有下载外部库下的 Go 模块。

标签: gobuildgolandgo-modules

解决方案


将所有src库下载到$GOPATH/pkg/mod

go mod download 

创建vendor目录 ( <project-name>/vendor) 使用vendor 标志

go mod vendor

1.14版本之前

使用标志构建vendor

go build -mod=vendor

或者

GOFLAGS="-mod=vendor" go build

1.14 及更高版本Go 模块

当主模块包含顶级vendor目录并且其go.mod文件指定 go 1.14 或更高版本时,go 命令现在默认-mod=vendor为接受该标志的操作。该标志的新值-mod=mod, 会导致 go 命令从模块缓存中加载模块(就像没有供应商目录存在时一样)。

project-name目录中执行(包含go.mod


推荐阅读