user1921476
user1921476

Reputation: 63

GoLand not detecting vendor packages under $GOPATH/pkg/mod?

Goland not detecting the imported modules from github.com. The modules are available in $GOPATH/pkg/mod directory but the imports are not being resolved. The vendor directory also have all the packages downloaded.

Goland Version : 2019.3.3 Go Version : Go 1.13.7

Under Preferences:

 - 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 Structure :

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

- External Libraries
  - GO SDK 1.13.7

Worth mentioning that, Goland is not downloading the Go modules under External libraries.

Upvotes: 0

Views: 2517

Answers (1)

kozmo
kozmo

Reputation: 4471

Download all src of libraries to $GOPATH/pkg/mod

go mod download 

Create vendor directory (<project-name>/vendor) use vendor flag

go mod vendor

Before 1.14 version

Build with vendor flag

go build -mod=vendor

or

GOFLAGS="-mod=vendor" go build

1.14 and higher (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).

Execute in project-name directory ( which contains go.mod)

Upvotes: 2

Related Questions