List<IncludedRuntimeModule> () { List<IncludedRuntimeModule> rootIncludedModules = new ArrayList<>(); Set<RuntimeModuleDescriptor> rootModules = new HashSet<>(); ProductModeMatcher matcher = new ProductModeMatcher(myProductMode); for (RawIncludedRuntimeModule rawRootModule : myRawRootModules) { IncludedRuntimeModule included = rawRootModule.resolve(myRepository); if (included != null && matcher.matches(included.getModuleDescriptor())) { rootIncludedModules.add(included); rootModules.add(included.getModuleDescriptor()); } } List<IncludedRuntimeModule> result = new ArrayList<>(rootIncludedModules); Set<RuntimeModuleDescriptor> visited = new HashSet<>(); for (IncludedRuntimeModule rootModule : rootIncludedModules) { collectDependencies(rootModule.getModuleDescriptor(), rootModules, visited, result); } return result; }