void (@NotNull Collection<? extends ExternalDependency> compileDependencies, @NotNull Collection<? extends ExternalDependency> runtimeDependencies) { Multimap<Collection<File>, ExternalDependency> filesToRuntimeDependenciesMap = HashMultimap.create(); for (ExternalDependency runtimeDependency : runtimeDependencies) { final Collection<File> resolvedFiles = getFiles(runtimeDependency); filesToRuntimeDependenciesMap.put(resolvedFiles, runtimeDependency); } for (ExternalDependency compileDependency : compileDependencies) { final Collection<File> resolvedFiles = getFiles(compileDependency); Collection<ExternalDependency> dependencies = filesToRuntimeDependenciesMap.get(resolvedFiles); final boolean hasRuntimeDependencies = !dependencies.isEmpty(); if (hasRuntimeDependencies) { runtimeDependencies.removeAll(dependencies); } else { ((AbstractExternalDependency)compileDependency).setScope(PROVIDED_SCOPE); } } }