Collection<ExternalDependency> (@NotNull SourceSet sourceSet) { Collection<ExternalDependency> result = new ArrayList<>(); // resolve compile dependencies CompileDependenciesProvider compileDependenciesProvider = new CompileDependenciesProvider(sourceSet, myProject).resolve(this); Collection<ExternalDependency> compileDependencies = compileDependenciesProvider.getDependencies(); // resolve runtime dependencies RuntimeDependenciesProvider runtimeDependenciesProvider = new RuntimeDependenciesProvider(sourceSet, myProject).resolve(this); Collection<ExternalDependency> runtimeDependencies = runtimeDependenciesProvider.getDependencies(); Multimap<Object, ExternalDependency> filesToDependenciesMap = collectCompileDependencies(compileDependenciesProvider, runtimeDependenciesProvider); filterCompileDepsFromRuntime(runtimeDependencies, filesToDependenciesMap); result.addAll(compileDependencies); result.addAll(runtimeDependencies); result = Lists.newArrayList(filter(result, isNotNull())); // merge file dependencies Set<File> compileClasspathFiles = getCompileClasspathFiles(sourceSet, "Java", "Groovy", "Scala"); Map<File, Integer> compileClasspathOrder = addIterationOrder(compileClasspathFiles); Set<File> runtimeClasspathFiles = getRuntimeClasspathFiles(sourceSet); Map<File, Integer> runtimeClasspathOrder = addIterationOrder(runtimeClasspathFiles); runtimeClasspathFiles.removeAll(compileClasspathFiles); runtimeClasspathFiles.removeAll(sourceSet.getOutput().getFiles()); compileClasspathFiles.removeAll(sourceSet.getOutput().getFiles()); Multimap<String, File> resolvedDependenciesMap = ArrayListMultimap.create(); resolvedDependenciesMap.putAll(CompileDependenciesProvider.SCOPE, compileDependenciesProvider.getFiles()); resolvedDependenciesMap.putAll(RuntimeDependenciesProvider.SCOPE, runtimeDependenciesProvider.getFiles()); Project rootProject = myProject.getRootProject(); for (ExternalDependency dependency : new DependencyTraverser(result)) { updateDependencyOrder(compileClasspathOrder, runtimeClasspathOrder, dependency); resolvedDependenciesMap.putAll(dependency.getScope(), getFiles(dependency)); if (dependency instanceof ExternalProjectDependency) { ExternalProjectDependency projectDependency = (ExternalProjectDependency)dependency; Project project = rootProject.findProject(projectDependency.getProjectPath()); SourceSet mainSourceSet; if ((mainSourceSet = findSourceSet(project, "main")) != null) { result.addAll(collectSourceSetOutputDirsAsSingleEntryLibraries(mainSourceSet, runtimeClasspathOrder, dependency.getScope())); } } } // remove processed files compileClasspathFiles.removeAll(resolvedDependenciesMap.get(CompileDependenciesProvider.SCOPE)); compileClasspathFiles.removeAll(resolvedDependenciesMap.get(PROVIDED_SCOPE)); runtimeClasspathFiles.removeAll(resolvedDependenciesMap.get(RuntimeDependenciesProvider.SCOPE)); runtimeClasspathFiles.removeAll(resolvedDependenciesMap.get(CompileDependenciesProvider.SCOPE)); runtimeClasspathFiles.removeAll(resolvedDependenciesMap.get(PROVIDED_SCOPE)); // try to map to libraries Collection<ExternalDependency> fileDependencies = new ArrayList<>(); fileDependencies.addAll(createLibraryDependenciesForFiles(compileClasspathFiles, CompileDependenciesProvider.SCOPE)); fileDependencies.addAll(createLibraryDependenciesForFiles(runtimeClasspathFiles, RuntimeDependenciesProvider.SCOPE)); for (ExternalDependency dependency : fileDependencies) { updateDependencyOrder(compileClasspathOrder, runtimeClasspathOrder, dependency); } result.addAll(fileDependencies); result.addAll(createFileCollectionDependencies(compileClasspathFiles, compileClasspathOrder, CompileDependenciesProvider.SCOPE)); result.addAll(createFileCollectionDependencies(runtimeClasspathFiles, runtimeClasspathOrder, RuntimeDependenciesProvider.SCOPE)); result.addAll(collectSourceSetOutputDirsAsSingleEntryLibraries(sourceSet, runtimeClasspathOrder, RuntimeDependenciesProvider.SCOPE)); collectProvidedDependencies(sourceSet, result); return removeDuplicates(result); }