public static void addScopesForSourceSets(Collection<? extends ModuleSourceSet> sets, Collection<String> unloadedModules, List<? super TargetTypeBuildScope> scopes, boolean forceBuild) {
    if (sets.isEmpty() && unloadedModules.isEmpty()) {
      return;
    }
    final Map<BuildTargetType<?>, Set<String>> targetsByType = new HashMap<>();
    final Function<BuildTargetType<?>, Set<String>> idsOf = targetType -> {
      Set<String> ids = targetsByType.get(targetType);
      if (ids == null) {
        ids = new HashSet<>();
        targetsByType.put(targetType, ids);
      }
      return ids;
    };
    for (ModuleSourceSet set : sets) {
      final BuildTargetType<?> targetType = toTargetType(set);
      assert targetType != null;
      idsOf.apply(targetType).add(set.getModule().getName());
    }
    if (!unloadedModules.isEmpty()) {
      for (JavaModuleBuildTargetType targetType : JavaModuleBuildTargetType.ALL_TYPES) {
        idsOf.apply(targetType).addAll(unloadedModules);
      }
    }

    for (Map.Entry<BuildTargetType<?>, Set<String>> entry : targetsByType.entrySet()) {
      TargetTypeBuildScope.Builder builder = TargetTypeBuildScope.newBuilder().setTypeId(entry.getKey().getTypeId()).setForceBuild(forceBuild);
      for (String targetId : entry.getValue()) {
        builder.addTargetId(targetId);
      }
      scopes.add(builder.build());
    }
  }
public static void addScopesForSourceSets(Collection<? extends ModuleSourceSet> sets, Collection<String> unloadedModules, List<? super TargetTypeBuildScope> scopes, boolean forceBuild)