The reason this approach does not work, has to do with the configuration in IntelliJ. That is why it will work from command line, just not in IntelliJ.
There are two ways to fix this:
- Go into Preferences -> Languages & Frameworks -> Go -> Go Modules (vgo) and make sure the box 'Vendoring mode' is not checked.
- Make sure you have a folder called 'vendor' in your IntelliJ project. Now the box 'Vendoring mode' can be safely checked.
With the first approach the dependencies defined in your go.mod
file might be re-downloaded, for example when the go project is run from a place where these dependencies are not in the local package registry.
With the second approach the dependencies are put in the 'vendor' folder and do not necessarily need to be re-downloaded, they are sort of made part of the project.