private @NotNull Map<String, GradleModuleResourceConfiguration> generateAffectedGradleModulesConfiguration(@NotNull CompileContext context) {
    final Map<String, GradleModuleResourceConfiguration> affectedGradleModuleConfigurations = new HashMap<>();

    final Map<String, ExternalProject> lazyExternalProjectMap = FactoryMap.create(
      gradleProjectPath1 -> externalProjectDataCache.getRootExternalProject(gradleProjectPath1));

    for (Module module : context.getCompileScope().getAffectedModules()) {
      if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module)) continue;

      final String gradleProjectPath = ExternalSystemApiUtil.getExternalRootProjectPath(module);
      assert gradleProjectPath != null;

      if (shouldBeBuiltByExternalSystem(module)) continue;

      final ExternalProject externalRootProject = lazyExternalProjectMap.get(gradleProjectPath);
      if (externalRootProject == null) {
        String message = GradleBundle.message("compiler.build.messages.gradle.configuration.not.found", module.getName());
        context.addMessage(CompilerMessageCategory.WARNING, message, null, -1, -1, null, Collections.singleton(module.getName()));
        continue;
      }

      Map<String, ExternalSourceSet> externalSourceSets = externalProjectDataCache.findExternalProject(externalRootProject, module);
      if (externalSourceSets.isEmpty()) {
        LOG.debug("Unable to find source sets config for module: " + module.getName());
        continue;
      }

      VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots(true);
      if (sourceRoots.length == 0) continue;

      GradleModuleResourceConfiguration resourceConfig = new GradleModuleResourceConfiguration();
      resourceConfig.id = new ModuleVersion(
        ExternalSystemApiUtil.getExternalProjectGroup(module),
        ExternalSystemApiUtil.getExternalProjectId(module),
        ExternalSystemApiUtil.getExternalProjectVersion(module));

      PathMapper pathMapper = null;
      for (ExternalSystemExecutionAware executionAware : ExternalSystemExecutionAware.getExtensions(GradleConstants.SYSTEM_ID)) {
        TargetEnvironmentConfigurationProvider provider = executionAware
          .getEnvironmentConfigurationProvider(gradleProjectPath, false, context.getProject());
        if (provider != null) {
          pathMapper = provider.getPathMapper();
          break;
        }
      }

      for (ExternalSourceSet sourceSet : externalSourceSets.values()) {
        addResources(resourceConfig.resources, sourceSet.getSources().get(ExternalSystemSourceType.RESOURCE),
                     sourceSet.getSources().get(ExternalSystemSourceType.SOURCE), pathMapper);
        addResources(resourceConfig.testResources, sourceSet.getSources().get(ExternalSystemSourceType.TEST_RESOURCE),
                     sourceSet.getSources().get(ExternalSystemSourceType.TEST), pathMapper);
      }

      boolean useCompilerOutputForResources = PlatformUtils.isFleetBackend();
      final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
      if (compilerModuleExtension != null &&
          (useCompilerOutputForResources || compilerModuleExtension.isCompilerOutputPathInherited())) {
        String outputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrl());
        for (ResourceRootConfiguration resource : resourceConfig.resources) {
          resource.targetPath = toRemote(pathMapper, outputPath);
        }

        String testOutputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrlForTests());
        for (ResourceRootConfiguration resource : resourceConfig.testResources) {
          resource.targetPath = toRemote(pathMapper, testOutputPath);
        }
      }

      affectedGradleModuleConfigurations.put(module.getName(), resourceConfig);
    }

    return affectedGradleModuleConfigurations;
  }
private @NotNull Map<String, GradleModuleResourceConfiguration> generateAffectedGradleModulesConfiguration(@NotNull CompileContext context)