go - 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 模块。
解决方案
将所有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
)
推荐阅读
- java - 在 Spark 中使用精确分位数还是近似分位数?
- javascript - 用于 attachEvent 的 Polyfill 删除 dhtmlx attachEvent 函数
- python - Pandas join/concat 操作合二为一以加入数据帧
- testing - 负载测试的性能指标?
- python - 运行 python 脚本时的一个简单错误
- c# - 如何在 Xamarin 表单项目中使用 NLog 记录信息
- python - pdf到csv文件转换的文本内容-如何?
- node.js - React 应用程序未在浏览器中运行。如何解决这个问题?
- kotlin - Kotlin 中的方法和成员函数
- html - 关于何时以及为什么需要在 HTML 中使用按钮标签的 value 属性的困惑