Module (@NotNull Path modulePath) { ModuleManager moduleManager = ModuleManager.getInstance(myProject); Module module; try { module = ApplicationManager.getApplication().runWriteAction((ThrowableComputable<Module, Exception>)() -> { return moduleManager.loadModule(modulePath); }); } catch (Exception e) { throw new RuntimeException(e); } myModulesToDispose.add(module); return module; }