void (@NotNull String name, @NotNull Path contentRoot, @NotNull Path path, @NotNull Project project) { String moduleType = JavaModuleType.getModuleType().getId(); Path moduleFile = path.resolve(name + ModuleFileType.DOT_DEFAULT_EXTENSION); ModuleManager moduleManager = ModuleManager.getInstance(project); ApplicationManager.getApplication().runWriteAction(() -> { Module module = moduleManager.newModule(moduleFile, moduleType); ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel(); model.addContentEntry(VfsUtilCore.pathToUrl(contentRoot.toString())); model.commit(); }); }