【问题标题】:GoLand not detecting vendor packages under $GOPATH/pkg/mod?GoLand 没有检测到 $GOPATH/pkg/mod 下的供应商包?
【发布时间】:2020-07-09 15:50:24
【问题描述】:

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

Goland 版本:2019.3.3 围棋版本:围棋 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 模块。

【问题讨论】:

  • 我们最近修复了一些相关的错误。你能更新到2019.3.4吗?有帮助吗?
  • $GOPATH/pkg/mod 与 vendoring 完全无关。

标签: go build goland go-modules


【解决方案1】:

将所有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 Modules)

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

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

【讨论】:

    猜你喜欢
    • 2020-05-14
    • 1970-01-01
    • 2017-04-27
    • 2017-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    • 1970-01-01
    相关资源
    最近更新 更多