boolean (boolean myBefore, @NotNull ProjectTaskContext context) { ProjectTaskScope taskScope = context.getUserData(ProjectTaskScope.KEY); if (taskScope == null) { return true; } Set<String> modulesToBuild = new LinkedHashSet<>(); Set<String> modulesToRebuild = new LinkedHashSet<>(); for (ModuleBuildTask task : taskScope.getRequestedTasks(ModuleBuildTask.class)) { String projectPath = ExternalSystemApiUtil.getExternalProjectPath(task.getModule()); if (projectPath == null) continue; if (task.isIncrementalBuild()) { modulesToBuild.add(projectPath); } else { modulesToRebuild.add(projectPath); } } boolean result = true; if (myBefore) { if (!modulesToRebuild.isEmpty()) { result = runTasks(modulesToRebuild, Phase.BEFORE_REBUILD); } if (result && !modulesToBuild.isEmpty()) { result = runTasks(modulesToBuild, Phase.BEFORE_COMPILE); } } else { if (!modulesToRebuild.isEmpty()) { result = runTasks(modulesToRebuild, Phase.AFTER_REBUILD); } if (result && !modulesToBuild.isEmpty()) { result = runTasks(modulesToBuild, Phase.AFTER_COMPILE); } } return result; }