Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not finding $GOPATH package imports #224

Closed
FAQinghere opened this issue May 3, 2013 · 14 comments
Closed

not finding $GOPATH package imports #224

FAQinghere opened this issue May 3, 2013 · 14 comments

Comments

@FAQinghere
Copy link

I cannot get the plugin to find the packages imported into my projects.

Right now I'm trying the simplest possible structure - exactly per the Go docs:

mine
$HOME/go/src/mycompany/myproject/hello.go
imported
$HOME/go/src/thirdparty/theirproject/say.go

import "theirproject/say"

go get

Everything works fine (predictably) from the command line. But still the plugin is not able to find the imported package.

I tried fiddling with the project structure (adding the gopath src directory as a library, etc), but to no avail.

Could anybody shed some light on how to get the plugin to pick up the installed packages (obviously located in $GOPATH/src)?

@tecbot
Copy link

tecbot commented May 3, 2013

I have the same problem on os x

@FAQinghere
Copy link
Author

Looking through the source, it seems that the plugin doesn't use the $GOPATH (to be fair, I think earlier Go docs didn't make the distinction between using $GOPATH and $GOROOT quite as clear as they do now).

In setting up the plugin you have to
1.) create symlinks for all of the imported package directories in your $GOPATH:
a. $GOROOT/src/pkg/ -> $GOPATH/src
ex. from within $GOROOT/src/pkg, ln -s $GOPATH/src/github.com
b. $GOROOT/pkg/target/ -> $GOPATH/pkg/target/
ex. from within $GOROOT/pkg/darwin_amd64, ln -s $GOPATH/pkg/darwin_amd64/code.google.com
2.) you MUST set up a source directory when creating the project (however, it can be an empty string, which will then cause the wizard to prompt you that it will set the project root as the source directory)

@tecbot
Copy link

tecbot commented May 3, 2013

yes, I use the workaround already (for the $GOPATH), but its bad.

@FAQinghere
Copy link
Author

Just confirmed with the Go guys, we should have a single $GOPATH with all libs and projects under its 'src' directory, and not have different 'src' directories within each project.

To make this work right now,

  1. set the src directory as an empty string (do NOT choose to not create one) in the project creation wizard
  2. symlink the $GOROOT to $GOPATH as mentioned above (need 2 symlinks) because the $GOROOT is used in import resolution

@jamra
Copy link

jamra commented May 8, 2013

This isn't working for me. I am on os x and my GOROOT is ~/go and GOPATH is ~/go/src. So far It cannot find the imports from github.com

EDIT: somehow, it works now. I had to restart intelliJ.

@pyanfield
Copy link

I have the same problem, can't find the GOPATH if it's not under GOROOT directory.

@FAQinghere
Copy link
Author

@pyanfield Yes, the plugin works pretty well, but it doesn't follow go conventions with regards to GOPATH. It wants to find all your libs in either your project directory, or your GOROOT, neither of which fits Go convention. It works if you symlink from your GOROOT to your GOPATH, as discussed above, because those two directories are both stable if you are using Go conventions (one GOPATH covering all your libs and projects). You might have to recreate the symlinks after upgrading Go, but otherwise you should be good.

As a side note, earlier in Go there was a tendency to put libs in the GOROOT, which gives some context to this plugin's behavior. I confirmed the current, "correct" convention directly with the Go team a couple months ago, but for some reason I wasn't able to explain it well enough to @mtoader ( see issue #215 ).

Nonetheless, for a conventional Go dev environment,
1.) Create the symlinks
2.) On the 2nd step of the new project creation wizard in the Golang Plugin, keep the "Create source directory" selection, but make it an empty string. It won't work if you choose the option not to create the directory.

Then everything will work fine under your $GOPATH/src/github.com/username/project

If you leave the "src" in the Create source directory dialogue, you'll get $GOPATH/src/github.com/username/project/src (oops).

@ddup2
Copy link

ddup2 commented Aug 11, 2014

Why this issue is closed? i still have the same issue with latest InteiJ 13.1.4 and golang plugin 0.9.15.3.
The same issue exists when importing some packages in same project with folder structures like "../common", any hints?

@No1zzz
Copy link

No1zzz commented Aug 16, 2014

Same here

@aldrin-ronco
Copy link

Me too

@thekostya
Copy link

the same problem on mac os

@dlsniper
Copy link
Member

Since we, the developers of the plugin, are developers just like you, the users of the plugin, getting comments on tickets with the content: "me too" helps us identify and fix issues just like it helps you when you receive issues like this in your daily activity.
As such I ask you to please send bug reports in the format that you'd expect to receive them else tickets like this will stay closed since: "It works on my machine" (and it really does work).

Thank you.

@mtoader
Copy link
Member

mtoader commented Oct 29, 2014

To provide some more context on the broader issue: The plugin will focus on supporting writing go code using the concept of Workspace (as described here: https://golang.org/doc/code.html#Workspaces).

This is the guidance on using relative imports paths: https://golang.org/cmd/go/#hdr-Relative_import_paths. The takeaways are:

  • if you are using the command line then by all means use them (this is not applicable to this issue as the resolving works differently)
  • if you are using relative imports in general it means that you are not using a workspace or you are not idiomatic.

We most likely not make any special effort to support relative imports if it proves too costly.

Also some of the issues reported here stem from another big problem with the plugin that we are in the course of resolving soonish. My instinct is to close this as it doesn't really provide a lot of value to the development of the plugin right now but i'll let it like this for a while until we have updated information on this.

@JackleZhang
Copy link

I have resolved this problem via mac's ln demand.
This problem is just how can your idea find the root package path.
For example, My $GOPATH is ~/mygo . I just create symbolic link like this.
ln -s $GOROOT/src ~/mygo
Mean while, In my idea, File -> Project Settings -> Libraries add GOPATH import my symbolic link like ~/mygo and restart idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests