private static @NotNull Map<String, ExternalSourceSet> findExternalProject(@NotNull ExternalProject parentProject,
                                                                             @NotNull String externalProjectId,
                                                                             boolean isSourceSet) {
    ArrayDeque<ExternalProject> queue = new ArrayDeque<>();
    queue.add(parentProject);

    ExternalProject externalProject;
    while ((externalProject = queue.pollFirst()) != null) {
      final String projectId = externalProject.getId();
      boolean isRelatedProject = projectId.equals(externalProjectId);
      final Map<String, ExternalSourceSet> result = new HashMap<>();
      for (Map.Entry<String, ? extends ExternalSourceSet> sourceSetEntry : externalProject.getSourceSets().entrySet()) {
        final String sourceSetName = sourceSetEntry.getKey();
        final String sourceSetId = projectId + ":" + sourceSetName;
        if (isRelatedProject || (isSourceSet && externalProjectId.equals(sourceSetId))) {
          result.put(sourceSetName, sourceSetEntry.getValue());
        }
      }
      if(!result.isEmpty() || isRelatedProject) return result;

      queue.addAll(externalProject.getChildProjects().values());
    }

    return Collections.emptyMap();
  }
private static @NotNull Map<String, ExternalSourceSet> findExternalProject(@NotNull ExternalProject parentProject,
                                                                             @NotNull String externalProjectId,
                                                                             boolean isSourceSet)