GoLand 没有检测到 $GOPATH/pkg/mod 下的 vendor 包?

标签 go build goland go-modules

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

戈兰版本: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 模块。

最佳答案

全部下载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)

When the main module contains a top-level vendor directory and its go.mod file specifies go 1.14 or higher, the go command now defaults to -mod=vendor for operations that accept that flag. A new value for that flag, -mod=mod, causes the go command to instead load modules from the module cache (as when no vendor directory is present).


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

关于GoLand 没有检测到 $GOPATH/pkg/mod 下的 vendor 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60910866/

相关文章:

go - go lang 中类似 slice 移位的函数

go - 在 Go 中发布 channel

xcode - 防止 Xcode 在任何文件更改时重建项目

Goland运行调试时无法获取正确的当前路径?

go - go get return go:标志需要一个参数:-mod

go - scanner.Scan() 在 GoLand 调试器中挂起

Golang - 为什么我不能在 GOPATH/src/project 中导入本地包,但可以在主目录中导入?

go - 启动守护进程但直到守护进程启动进程在 golang 中完成后才继续

java - 与 Maven 相比,构建 Java Web 应用程序的更好、更简单和更现代的方法是什么?

android - 如何在不从项目中删除的情况下从android中的构建路径中排除lib文件