-4

My project consists of multiple go modules which I need to work on simultaneously. This is made easy by using the replace directive in the go.mod file.

Further, in order to prevent this change from getting accidentally checked in, the go tools (starting with version 1.14) offer a -modfile switch which lets me put the replace directive in a go.local.mod file instead. This is super convenient.

Unfortunately, I am unable to get Goland to pick up this go.local.mod instead of go.mod.

I have tried setting the GOMOD environment variable under Preferences -> Go -> Go Modules to point to my go.local.mod file. This did not do what I expected it to (which is to use the go.local.mod file instead of go.mod) Not surprisingly, this did not work since GOMOD is supposed to be readonly (as pointed out to me in the comments).

For now I can go back to putting the replace directive in the go.mod file and using commit hooks to prevent accidental check-in (and Goland has some tooling to perform this check as well) However, it would be super convenient if Goland can recognize this new -modfile switch that go has added. Figured I would ask to make sure I'm not missing something obvious here.

Thanks!

cosmiczilch
  • 43
  • 2
  • 7
  • You're right. Its not. But there is an "OTHER" option while setting env variables. So I tried it. Honestly, I don't really care if this is achieved using the GOMOD env-var. I'd just appreciate a way to do this, is all. – cosmiczilch Jun 08 '20 at 17:57
  • `GOMOD` is specifically documented as not being read from the environment. Are you looking for the `GOFLAGS` variable perhaps? – JimB Jun 08 '20 at 18:04
  • Apologies. Let me edit my question to remove the focus on GOMOD. What I am trying to achieve is to get Goland to use a different go.mod file than the default (i.e. the equivalent of the -modfile switch in go tooling) – cosmiczilch Jun 08 '20 at 18:10
  • I haven't tried it, but what about adding -modfile in the "Run Configuration"? – Bruno Reis Jun 08 '20 at 19:06
  • Did you try `GOFLAGS`? Does `GOFLAGS=-modfile=./go.local.mod` do what you want? – JimB Jun 08 '20 at 19:29
  • Just tried GOFLAGS, didn't work. Also, adding -modfile to Run configuration might work for Running the program. But i'm more concerned with editing the right files. i.e. when I follow through on a symbol in the other module I want to be editing my local checked out copy of it. – cosmiczilch Jun 09 '20 at 02:13

1 Answers1

1

At the moment, 2020.1.3 stable release, this is not supported. See the related issue for future updates on this.

dlsniper
  • 7,188
  • 1
  • 35
  • 44