void (@NotNull Project project, @NotNull ProjectTaskContext context, @Nullable ProjectTaskNotification callback, @NotNull Collection<? extends ModuleBuildTask> moduleBuildTasks) { if (moduleBuildTasks.isEmpty()) return; MavenRunner mavenRunner = MavenRunner.getInstance(project); MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(project); MavenExplicitProfiles explicitProfiles = mavenProjectsManager.getExplicitProfiles(); Map<MavenProject, List<MavenProject>> rootProjectsToModules = new HashMap<>(); boolean buildOnlyResources = false; for (ModuleBuildTask moduleBuildTask : moduleBuildTasks) { MavenProject mavenProject = mavenProjectsManager.findProject(moduleBuildTask.getModule()); if (mavenProject == null) continue; buildOnlyResources = buildOnlyResources || moduleBuildTask instanceof ModuleResourcesBuildTask; MavenProject rootProject = mavenProjectsManager.findRootProject(mavenProject); rootProjectsToModules.computeIfAbsent(rootProject, p -> new ArrayList<>()).add(mavenProject); } boolean clean = moduleBuildTasks.stream().anyMatch(task -> !(task instanceof ModuleFilesBuildTask) && !task.isIncrementalBuild()); boolean compileOnly = moduleBuildTasks.stream().allMatch(task -> task instanceof ModuleFilesBuildTask); boolean includeDependentModules = moduleBuildTasks.stream().anyMatch(ModuleBuildTask::isIncludeDependentModules); String goal = getGoal(buildOnlyResources, compileOnly); List<MavenRunnerParameters> commands = new ArrayList<>(); for (Map.Entry<MavenProject, List<MavenProject>> entry : rootProjectsToModules.entrySet()) { ParametersList parameters = new ParametersList(); if (clean) { parameters.add("clean"); } parameters.add(goal); List<MavenProject> mavenProjects = entry.getValue(); if (!includeDependentModules) { if (mavenProjects.size() > 1) { parameters.add("--projects"); parameters.add(mavenProjects.stream() .map(MavenProject::getMavenId) .map(mavenId -> mavenId.getGroupId() + ":" + mavenId.getArtifactId()) .collect(joining(","))); } else { parameters.add("--non-recursive"); } } VirtualFile pomFile = (mavenProjects.size() > 1 ? entry.getKey() : mavenProjects.get(0)).getFile(); commands.add(new MavenRunnerParameters(true, pomFile.getParent().getPath(), pomFile.getName(), parameters.getList(), explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles())); } runBatch(project, mavenRunner, "Maven Build", commands, context, callback); }