Set<ExternalDependency> (ResolvedDependencyResult dependencyResult) { Set<ExternalDependency> result = new LinkedHashSet<>(); final ResolvedComponentResult componentResult = dependencyResult.getSelected(); if (!myVisitedComponentResults.add(getKey(componentResult))) { return Collections.emptySet(); } final ComponentIdentifier resultId = componentResult.getId(); ModuleComponentIdentifier componentIdentifier = resultId instanceof ModuleComponentIdentifier ? (ModuleComponentIdentifier)resultId : toComponentIdentifier(componentResult.getModuleVersion()); String name = componentResult.getModuleVersion().getName(); String group = componentResult.getModuleVersion().getGroup(); String version = componentResult.getModuleVersion().getVersion(); ComponentSelectionReason reason = componentResult.getSelectionReason(); Object description = invokeMethod(reason, "getDescription"); String selectionReason = description == null ? "" : description.toString(); boolean resolveFromArtifacts = resultId instanceof ModuleComponentIdentifier; if (resultId instanceof ProjectComponentIdentifier) { ProjectComponentIdentifier projectComponentIdentifier = (ProjectComponentIdentifier)resultId; Collection<ProjectDependency> projectDependencies = configurationProjectDependencies.get(componentIdentifier); Collection<Configuration> dependencyConfigurations; String projectPath = projectComponentIdentifier.getProjectPath(); boolean currentBuild; if (is31orBetter) { currentBuild = projectComponentIdentifier.getBuild().isCurrentBuild(); } else { currentBuild = true; } if (projectDependencies.isEmpty()) { Project dependencyProject = myProject.findProject(projectPath); if (dependencyProject != null && currentBuild) { Configuration dependencyProjectConfiguration = dependencyProject.getConfigurations().findByName(Dependency.DEFAULT_CONFIGURATION); if (dependencyProjectConfiguration != null) { dependencyConfigurations = Collections.singleton(dependencyProjectConfiguration); } else { dependencyConfigurations = Collections.emptySet(); } } else { dependencyConfigurations = Collections.emptySet(); resolveFromArtifacts = true; selectionReason = "composite build substitution"; } } else { dependencyConfigurations = new ArrayList<>(); for (ProjectDependency dependency : projectDependencies) { Configuration targetConfiguration = getTargetConfiguration(dependency); if(targetConfiguration != null) { dependencyConfigurations.add(targetConfiguration); } } } for (Configuration it : dependencyConfigurations) { DefaultExternalProjectDependency dependency = createProjectDependency(componentResult, projectPath, it); if (!componentResult.equals(dependencyResult.getFrom())) { dependency.getDependencies().addAll( buildExternalDependencies(componentResult.getDependencies()) ); } result.add(dependency); resolvedDepsFiles.addAll(dependency.getProjectDependencyArtifacts()); if (!it.getName().equals(Dependency.DEFAULT_CONFIGURATION)) { List<File> files = new ArrayList<>(); PublishArtifactSet artifacts = it.getArtifacts(); if (!artifacts.isEmpty()) { PublishArtifact artifact = artifacts.iterator().next(); final MetaProperty taskProperty = DefaultGroovyMethods.hasProperty(artifact, "archiveTask"); if (taskProperty != null && (taskProperty.getProperty(artifact) instanceof AbstractArchiveTask)) { AbstractArchiveTask archiveTask = (AbstractArchiveTask)taskProperty.getProperty(artifact); resolvedDepsFiles.add(new File(reflectiveCall(archiveTask, "getDestinationDir", File.class), reflectiveCall(archiveTask, "getArchiveName", String.class))); try { final Method mainSpecGetter = AbstractCopyTask.class.getDeclaredMethod("getMainSpec"); mainSpecGetter.setAccessible(true); Object mainSpec = mainSpecGetter.invoke(archiveTask); final List<MetaMethod> sourcePathGetters = DefaultGroovyMethods.respondsTo(mainSpec, "getSourcePaths", new Object[]{}); if (!sourcePathGetters.isEmpty()) { Set<Object> sourcePaths = (Set<Object>)sourcePathGetters.get(0).doMethodInvoke(mainSpec, new Object[]{}); if (sourcePaths != null) { for (Object path : sourcePaths) { if (path instanceof String) { File file = new File((String)path); if (file.isAbsolute()) { files.add(file); } } else if (path instanceof SourceSetOutput) { files.addAll(((SourceSetOutput)path).getFiles()); } } } } } catch (Exception e) { throw new RuntimeException(e); } } } if (!files.isEmpty()) { final DefaultFileCollectionDependency fileCollectionDependency = new DefaultFileCollectionDependency(files); fileCollectionDependency.setScope(scope); result.add(fileCollectionDependency); resolvedDepsFiles.addAll(files); } } } } if (resolveFromArtifacts) { Collection<ResolvedArtifact> artifacts = artifactMap.get(componentResult.getModuleVersion()); if (artifacts.isEmpty()) { result.addAll( buildExternalDependencies(componentResult.getDependencies()) ); } boolean first = true; for (ResolvedArtifact artifact : artifacts) { String packaging = artifact.getExtension(); String classifier = artifact.getClassifier(); final ExternalDependency dependency; if (isProjectDependencyArtifact(artifact)) { ProjectComponentIdentifier artifactComponentIdentifier = (ProjectComponentIdentifier)artifact.getId().getComponentIdentifier(); dependency = new DefaultExternalProjectDependency(); DefaultExternalProjectDependency dDep = (DefaultExternalProjectDependency)dependency; dDep.setName(name); dDep.setGroup(group); dDep.setVersion(version); dDep.setScope(scope); dDep.setSelectionReason(selectionReason); dDep.setProjectPath(artifactComponentIdentifier.getProjectPath()); dDep.setConfigurationName(Dependency.DEFAULT_CONFIGURATION); Collection<ResolvedArtifact> resolvedArtifacts = artifactMap.get(componentResult.getModuleVersion()); List<File> files = new ArrayList<>(resolvedArtifacts.size()); for (ResolvedArtifact resolvedArtifact : resolvedArtifacts) { files.add(resolvedArtifact.getFile()); } dDep.setProjectDependencyArtifacts(files); GradleSourceSetCachedFinder sourceSetFinder = GradleSourceSetCachedFinder.getInstance(myContext); dDep.setProjectDependencyArtifactsSources(sourceSetFinder.findArtifactSources(files)); resolvedDepsFiles.addAll(dDep.getProjectDependencyArtifacts()); } else { dependency = new DefaultExternalLibraryDependency(); DefaultExternalLibraryDependency dDep = (DefaultExternalLibraryDependency)dependency; dDep.setName(name); dDep.setGroup(group); dDep.setPackaging(packaging); dDep.setClassifier(classifier); dDep.setVersion(version); dDep.setScope(scope); dDep.setSelectionReason(selectionReason); dDep.setFile(artifact.getFile()); ComponentArtifactsResult artifactsResult = componentResultsMap.get(componentIdentifier); if (artifactsResult != null) { ResolvedArtifactResult sourcesResult = findMatchingArtifact(artifact, artifactsResult, SourcesArtifact.class); if (sourcesResult != null) { ((DefaultExternalLibraryDependency)dependency).setSource(sourcesResult.getFile()); } ResolvedArtifactResult javadocResult = findMatchingArtifact(artifact, artifactsResult, JavadocArtifact.class); if (javadocResult != null) { ((DefaultExternalLibraryDependency)dependency).setJavadoc(javadocResult.getFile()); } } } if (first) { dependency.getDependencies().addAll( buildExternalDependencies(componentResult.getDependencies()) ); first = false; } result.add(dependency); resolvedDepsFiles.add(artifact.getFile()); } } return result; }