Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't IntelliJ IDEA import local packages in Go project?

I'm using Idea plugin for Go to work with my project. The structure of my project is the following:

enter image description here

controller, entity, model, repository etc - are local packages (where one can use another).

Unfortunately, Idea can't import one local package from another:

enter image description here

enter image description here

With remote packages everything is just fine.

My project settings:

enter image description here

enter image description here

What am I doing wrong?

like image 293
Dmitry Papka Avatar asked Oct 07 '14 19:10

Dmitry Papka


People also ask

Does IntelliJ work with Go?

The Go functionality in IntelliJ IDEA is supported by the Go plugin. The Go plugin provides support of all the features that are available in GoLand, the standalone IDE for Go developers.

How do I import a Golang project into IntelliJ?

Open an existing projectIn the Welcome to IntelliJ IDEA dialog, click Open. Alternatively, click File | Open. In the file browser, navigate to a folder with project files and click Open…. Click OK.

How do I import a package into IntelliJ?

Import packages instead of single classes IntelliJ IDEA suggests to import single classes by default. You can change the settings to import entire packages instead. In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Code Style | Java | Imports.


2 Answers

In my case enabling Enable Go modules integration helped.

enter image description here

like image 195
kmieciu Avatar answered Sep 20 '22 08:09

kmieciu


you need to follow the correct project structure - https://golang.org/doc/code.html

basically, an environment variable called GOPATH should be set to your workspace root, such as ~/dev/go

in $GOPATH/src all the source code lives, for example, when you get a remote package from github, like go get github.com/someone/somepackage, the source code will be downloaded to $GOPATH/src/github.com/someone/somepackage and the import path from within a .go file is `"github.com/someone/somepackage".

your own code should live under $GOPATH/src as well, let's say it's $GOPATH/src/me/myproject, then your import path for entity and model are "me/myproject/entity" and "me/myproject/model"

like image 34
Gal Ben-Haim Avatar answered Sep 19 '22 08:09

Gal Ben-Haim