How do I share a local import in a way that GoLand understands it? (it shows non-existing errors)


I want to create two projects, and they should share the same local import. If I don't share it between them but each project gets it's own copy, then there is no problem at all.

This on-the-fly-analysis in GoLand (the error markings in the code editor) is happy with imports like "./somelib". But it will show non-existing errors with "../somelib".

It looks like the GoLand analyzer can't find the directory when the import starts with dot dot. Whereas the golang compiler compiles just fine.

And I am .. well.. just irritated by the red text that GoLand shows. I though about changing the error color, but I didn't want to do that. It's really good for errors. Just not for non-existing errors.



GoLand 2019.2.2
Build #GO-192.6603.35, built on September 11, 2019
Licensed to GoLand Evaluator
Expiration date: October 20, 2019
Runtime version: 11.0.3+12-b304.56 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 725M
Cores: 4
Registry: run.processes.with.pty=false, ide.completion.variant.limit=500,
Non-Bundled Plugins:


To reproduce, create two projects, using Windows 10, and try to share code via an outer directory.

Btw, I did find a thread about non-existing errors in the editor and followed some solution, namely File -> Invalidate Cache, but that didn't help.

And I dismissed the idea of creating a library within the standard libraries, because I didn't want it to be organized wrongly, and differently from how I would organize it without GoLand.

And I couldn't find any feature like additional installed libraries in golang. I'm a beginner golang user, don't know many ways to do it.


Am I right that all three directories are located under GOPATH and you don't use Go Modules?


No, none of the directories is in GOPATH. I'm working on a "portable" project so to say. I mean, I sometimes use my notebook instead of my desktop, and so I don't want to make the project depend on a modified Go installation.

I'll try adding the directories to the GOPATH, as that is within the project settings, I understand. Will report if it helps. Thanks a lot!


The whole thing consists only of this:
Fresh Windows 10 install
Download and install GoLand
Download and install Go

As project create three directories


And now it's possible to let both project A and B import from that local package by just doing import "../the_local_lib_package" in both.

It works without GoLand, by using just a batch file to compile for example. With GoLand it works, too, but I will get red text.


In general, it should work as GoLand supports relative import paths. Please check that you don't have any integration enabled under Settings | Go | Go Modules and Dep


Yep, this works, again thanks!

Settings -> Project Structure -> Add Content Root
There one just needs to add the directory that contains the shared package.


No, I don't think have the integration enabled willingly.

I just looked into it, "Enable Dep Integration" is currently unchecked, and I believe it always was.

But I did install Go seperately after installing GoLand, maybe something went wrong there and I could try to use the downloader in GoLand, the next time when I install the whole thing again.


What about Go Modules integration? Is it disabled as well?


Please sign in to leave a comment.