GoLand project in a submodule directory can't find `go.mod` file in parent directory. Can a submodule GoLand project integrate with rest of module?

GoLand project in a submodule directory can't find `go.mod` file in parent directory. Can a submodule GoLand project integrate with rest of module?

  

I have a small monorepo of Go code (as well as node/js/ts/vue/etc for frontend applications, but that should be irrelevant). There is a single go.mod in the repo root directory. I'm trying to create GoLand projects in various submodules of the monorepo, but it seems GoLand isn't detecting the root go.mod file. Example file structure:

root/
  go.mod  -- module named "mymodule"
  go.sum
  foo/
    .idea/
    main.go
  bar/
    .idea/
    main.go
  libs/
    go/
      mylib/
        mylib.go

In the foo and bar submodules/projects, GoLand is 1) reporting 'go.mod' file is absent, 2) saying it can't resolve imports from mymodule/libs/go/mylib. Command-line go operations (building, getting, etc) are functioning and detecting the root go.mod properly.

Is there a way to configure GoLand to recognize a project as part of a module from a parent directory?

Answer

I'm afraid that GoLand doesn't check any files outside of the opened project. Hence, the import is not resolved in case you open Foo or Bar directories. What you can try is to open the root directory with the mod.go file instead and work from there.

© 2024 Dagalaxy. All rights reserved.