void (@NotNull final Project project) { // We want to automatically refresh linked projects on gradle service directory change. MessageBusConnection connection = project.getMessageBus().connect(); connection.subscribe(GradleSettings.getInstance(project).getChangesTopic(), new GradleSettingsListener() { @Override public void onServiceDirectoryPathChange(@Nullable String oldPath, @Nullable String newPath) { for (GradleProjectSettings projectSettings : GradleSettings.getInstance(project).getLinkedProjectsSettings()) { ExternalProjectsManager.getInstance(project).getExternalProjectsWatcher().markDirty(projectSettings.getExternalProjectPath()); } } @Override public void onGradleHomeChange(@Nullable String oldPath, @Nullable String newPath, @NotNull String linkedProjectPath) { ExternalProjectsManager.getInstance(project).getExternalProjectsWatcher().markDirty(linkedProjectPath); } @Override public void onGradleDistributionTypeChange(DistributionType currentValue, @NotNull String linkedProjectPath) { ExternalProjectsManager.getInstance(project).getExternalProjectsWatcher().markDirty(linkedProjectPath); } @Override public void onBuildDelegationChange(boolean delegatedBuild, @NotNull String linkedProjectPath) { if (!updateOutputRoots(delegatedBuild, linkedProjectPath)) { ExternalProjectsManager.getInstance(project).getExternalProjectsWatcher().markDirty(linkedProjectPath); } } private boolean updateOutputRoots(boolean delegatedBuild, @NotNull String linkedProjectPath) { ExternalProjectInfo projectInfo = ProjectDataManager.getInstance().getExternalProjectData(project, GradleConstants.SYSTEM_ID, linkedProjectPath); if (projectInfo == null) return false; String buildNumber = projectInfo.getBuildNumber(); if (buildNumber == null) return false; final DataNode<ProjectData> projectStructure = projectInfo.getExternalProjectStructure(); if (projectStructure == null) return false; String title = ExternalSystemBundle.message("progress.refresh.text", projectStructure.getData().getExternalName(), projectInfo.getProjectSystemId().getReadableName()); ProgressManager.getInstance().run(new Task.Backgroundable(project, title, false) { @Override public void run(@NotNull ProgressIndicator indicator) { UnindexedFilesScannerExecutor.getInstance(project).suspendScanningAndIndexingThenRun(title, () -> { for (DataNode<ModuleData> moduleDataNode : findAll(projectStructure, ProjectKeys.MODULE)) { moduleDataNode.getData().useExternalCompilerOutput(delegatedBuild); for (DataNode<GradleSourceSetData> sourceSetDataNode : findAll(moduleDataNode, GradleSourceSetData.KEY)) { sourceSetDataNode.getData().useExternalCompilerOutput(delegatedBuild); } configureExcludeOutDir(moduleDataNode, delegatedBuild); } ProjectDataManager.getInstance().importData(projectStructure, project); }); } }); return true; } }); // We used to assume that gradle scripts are always named 'build.gradle' and kept path to that build.gradle file at ide settings. // However, it was found out that that is incorrect assumption (IDEA-109064). Now we keep paths to gradle script's directories // instead. However, we don't want to force old users to re-import gradle projects because of that. That's why we check gradle // config and re-point it from build.gradle to the parent dir if necessary. Map<String, String> adjustedPaths = patchLinkedProjects(project); if (adjustedPaths == null) { return; } GradleLocalSettings localSettings = GradleLocalSettings.getInstance(project); patchRecentTasks(adjustedPaths, localSettings); patchAvailableProjects(adjustedPaths, localSettings); }