Collection<ExternalDependency> (@Nullable Configuration configuration, @Nullable String scope) { if (configuration == null) { return emptySet(); } // following statement should trigger parallel resolution of configurations artifacts // all subsequent iteration are expected to use cached results. try { configuration.getIncoming().artifactView(new Action<ArtifactView.ViewConfiguration>() { @Override public void execute(@NotNull ArtifactView.ViewConfiguration configuration) { configuration.setLenient(true); } }).getArtifacts().getArtifacts(); } catch (Exception ignore) {} LenientConfiguration lenientConfiguration = configuration.getResolvedConfiguration().getLenientConfiguration(); ResolutionResult resolutionResult = configuration.getIncoming().getResolutionResult(); List<ComponentIdentifier> components = new ArrayList<>(); Map<ResolvedDependency, Set<ResolvedArtifact>> resolvedArtifacts = new LinkedHashMap<>(); Map<ModuleVersionIdentifier, ResolvedDependencyResult> transformedProjectDependenciesResultMap = null; for (ResolvedDependency dependency : lenientConfiguration.getAllModuleDependencies()) { try { Set<ResolvedArtifact> moduleArtifacts = dependency.getModuleArtifacts(); for (ResolvedArtifact artifact : moduleArtifacts) { if ((artifact.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier)) continue; components.add(toComponentIdentifier(artifact.getModuleVersion().getId())); } resolvedArtifacts.put(dependency, moduleArtifacts); } catch (GradleException e) { if (transformedProjectDependenciesResultMap == null) { transformedProjectDependenciesResultMap = new HashMap<>(); for (DependencyResult dependencyResult : resolutionResult.getAllDependencies()) { ComponentSelector resultRequested = dependencyResult.getRequested(); if (dependencyResult instanceof ResolvedDependencyResult && resultRequested instanceof ProjectComponentSelector) { ResolvedComponentResult resolvedComponentResult = ((ResolvedDependencyResult)dependencyResult).getSelected(); ModuleVersionIdentifier selectedResultVersion = resolvedComponentResult.getModuleVersion(); transformedProjectDependenciesResultMap.put(selectedResultVersion, (ResolvedDependencyResult)dependencyResult); } } } resolvedArtifacts.put(dependency, Collections.emptySet()); } catch (Exception ignore) { // ignore other artifact resolution exceptions } } Map<ComponentIdentifier, ComponentArtifactsResult> auxiliaryArtifactsMap = buildAuxiliaryArtifactsMap(configuration, components); Collection<FileCollectionDependency> sourceSetsOutputDirsRuntimeFileDependencies = new LinkedHashSet<>(); Collection<ExternalDependency> artifactDependencies = new LinkedHashSet<>(); Set<String> resolvedFiles = new HashSet<>(); Map<String, DefaultExternalProjectDependency> resolvedProjectDependencies = new HashMap<>(); GradleSourceSetCachedFinder sourceSetFinder = GradleSourceSetCachedFinder.getInstance(myContext); for (Map.Entry<ResolvedDependency, Set<ResolvedArtifact>> resolvedDependencySetEntry : resolvedArtifacts.entrySet()) { ResolvedDependency resolvedDependency = resolvedDependencySetEntry.getKey(); Set<ResolvedArtifact> artifacts = resolvedDependencySetEntry.getValue(); for (ResolvedArtifact artifact : artifacts) { File artifactFile = artifact.getFile(); if (resolvedFiles.contains(artifactFile.getPath())) { continue; } resolvedFiles.add(artifactFile.getPath()); String artifactPath = sourceSetFinder.findArtifactBySourceSetOutputDir(artifactFile.getPath()); if (artifactPath != null) { artifactFile = new File(artifactPath); if (resolvedFiles.contains(artifactFile.getPath())) { continue; } resolvedFiles.add(artifactFile.getPath()); } AbstractExternalDependency dependency; ModuleVersionIdentifier moduleVersionIdentifier = artifact.getModuleVersion().getId(); if (artifact.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier) { if (RUNTIME_SCOPE.equals(scope)) { SourceSet sourceSet = sourceSetFinder.findByArtifact(artifactFile.getPath()); if (sourceSet != null) { FileCollectionDependency outputDirsRuntimeFileDependency = resolveSourceSetOutputDirsRuntimeFileDependency(sourceSet.getOutput()); if (outputDirsRuntimeFileDependency != null) { sourceSetsOutputDirsRuntimeFileDependencies.add(outputDirsRuntimeFileDependency); } } } ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier)artifact.getId().getComponentIdentifier(); BuildIdentifier buildIdentifier = projectComponentIdentifier.getBuild(); String buildName; if (IS_83_OR_BETTER) { buildName = buildIdentifier.getBuildPath(); } else { buildName = buildIdentifier.getName(); } String projectPath = projectComponentIdentifier.getProjectPath(); String key = buildName + "_" + projectPath + "_" + resolvedDependency.getConfiguration(); DefaultExternalProjectDependency projectDependency = resolvedProjectDependencies.get(key); if (projectDependency != null) { Set<File> projectDependencyArtifacts = new LinkedHashSet<>(projectDependency.getProjectDependencyArtifacts()); projectDependencyArtifacts.add(artifactFile); projectDependency.setProjectDependencyArtifacts(projectDependencyArtifacts); Set<File> artifactSources = new LinkedHashSet<>(projectDependency.getProjectDependencyArtifactsSources()); artifactSources.addAll(sourceSetFinder.findArtifactSources(singleton(artifactFile))); projectDependency.setProjectDependencyArtifactsSources(artifactSources); continue; } else { projectDependency = new DefaultExternalProjectDependency(); resolvedProjectDependencies.put(key, projectDependency); } dependency = projectDependency; String projectName = projectComponentIdentifier.getProjectName(); // since 4.5 projectDependency.setName(projectName); projectDependency.setGroup(resolvedDependency.getModuleGroup()); projectDependency.setVersion(resolvedDependency.getModuleVersion()); projectDependency.setScope(scope); projectDependency.setProjectPath(projectPath); projectDependency.setConfigurationName(resolvedDependency.getConfiguration()); Set<File> projectArtifacts = singleton(artifactFile); projectDependency.setProjectDependencyArtifacts(projectArtifacts); projectDependency.setProjectDependencyArtifactsSources(sourceSetFinder.findArtifactSources(projectArtifacts)); } else { DefaultExternalLibraryDependency libraryDependency = new DefaultExternalLibraryDependency(); libraryDependency.setName(moduleVersionIdentifier.getName()); libraryDependency.setGroup(moduleVersionIdentifier.getGroup()); libraryDependency.setVersion(moduleVersionIdentifier.getVersion()); libraryDependency.setFile(artifactFile); ComponentArtifactsResult artifactsResult = auxiliaryArtifactsMap.get(artifact.getId().getComponentIdentifier()); if (artifactsResult != null) { Set<ArtifactResult> sourceArtifactResults = artifactsResult.getArtifacts(SourcesArtifact.class); for (ArtifactResult sourceArtifactResult : sourceArtifactResults) { if (sourceArtifactResult instanceof ResolvedArtifactResult) { libraryDependency.setSource(((ResolvedArtifactResult)sourceArtifactResult).getFile()); break; } } Set<ArtifactResult> javadocArtifactResults = artifactsResult.getArtifacts(JavadocArtifact.class); for (ArtifactResult javadocArtifactResult : javadocArtifactResults) { if (javadocArtifactResult instanceof ResolvedArtifactResult) { libraryDependency.setJavadoc(((ResolvedArtifactResult)javadocArtifactResult).getFile()); break; } } } libraryDependency.setPackaging(artifact.getExtension()); libraryDependency.setScope(scope); libraryDependency.setClassifier(artifact.getClassifier()); dependency = libraryDependency; } artifactDependencies.add(dependency); } if (transformedProjectDependenciesResultMap == null || !artifacts.isEmpty()) continue; ExternalProjectDependency projectDependency = getFailedToTransformProjectArtifactDependency( resolvedDependency, transformedProjectDependenciesResultMap, resolvedProjectDependencies, scope); if (projectDependency != null) { artifactDependencies.add(projectDependency); } } Collection<FileCollectionDependency> otherFileDependencies = resolveOtherFileDependencies(resolvedFiles, configuration, scope); Collection<ExternalDependency> result = new LinkedHashSet<>(); result.addAll(sourceSetsOutputDirsRuntimeFileDependencies); result.addAll(otherFileDependencies); result.addAll(artifactDependencies); addUnresolvedDependencies(result, lenientConfiguration, scope); return result; }