Question: I have a small program which calls multiple functions from the `main()` function and in each of the functions there is a small probability, that an error occurs. In order to be compatible with the existing monitoring system, I need to make a file to `/var/tmp/error_triggered/` directory if there was at least one error or remove the file from this directory if there were no errors. One way to do this is to use variable with global scope:

```
#!/usr/bin/env python3

import os
import random
from pathlib import Path

def f1():
  global error
  for i in range(1, 5):
    if random.randint(0, 9) == 0:
      error = 1

def f2():
  global error
  for i in range(1, 5):
    if random.randint(0, 9) == 0:
      error = 1

def main():
  f1()
  f2()

if __name__ == '__main__':
  error = 0
  main()
  if error == 1:
    Path('/var/tmp/error_triggered/' + os.path.splitext(os.path.basename(__file__))[0]).touch()
  else:
    Path('/var/tmp/error_triggered/' + os.path.splitext(os.path.basename(__file__))[0]).unlink(missing_ok=True)

```

It is usually a bad practice to modify a global variable from inside functions. Is it justified here? Or is there a better approach to solve this problem?

Answer: 
For the IDE to resolve classes and imports from dependant module these classes should exist and they must be located in dependant module's [**source** directory](https://www.jetbrains.com/help/idea/content-roots.html#folder-categories). Looks like the classes are generated into a directory which is not recognized by IDE as a **source** directory. Try adding this generated directory as a Gradle source set. In moduleA's Gradel build file add:

```
sourceSets {
    main {
        java {
            srcDirs = ['build/generated/source/proto/main/java']
        }
    }
}

```

where `'build/generated/source/proto/main/java'` - the directory where sources are generated.

There is a related issue for IntelliJ IDEA: [IDEA-209418](https://youtrack.jetbrains.com/issue/IDEA-209418).
This is same as using proto generated code in the same module, it needs to be there first before it can be picked up by IDE.

Such dependencies cannot be resolved statically. Proto generated classes are available only after `moduleA` is *built*. You would need to build `moduleA` at least once (and refresh the IDE imports if necessary) to make its generated code reachable to `moduleB`.