in buildSrc/src/main/java/com/uber/okbuck/core/model/base/Scope.java [279:415]
private void extractConfiguration(Configuration configuration) {
DependencyFactory factory = ProjectUtil.getDependencyFactory(project);
ExternalDependenciesExtension externalDependenciesExtension =
ProjectUtil.getExternalDependencyExtension(project);
// Add raw dependency to dep cache. Used to resolved 3rdparty
// dependencies when versionless is enabled.
depCache.addDependencies(configuration.getAllDependencies());
// TODO: Move to generic way which defines the first level dependencies
// rather than collecting them from a global project which contains all.
// Skip resolving gradle configurations which contains all dependencies
// in the classpath to prevent doing un-needed work.
if (externalDependenciesExtension.resoleOnlyThirdParty()
&& configuration.getName().toLowerCase().contains("classpath")) {
return;
}
// Get first level project deps defined for the project's configuration
Set<String> projectFirstLevel =
configuration
.getAllDependencies()
.withType(ProjectDependency.class)
.stream()
.map(dependency -> dependency.getDependencyProject().getPath())
.collect(Collectors.toSet());
// Get first level external deps defined for the project's configuration
Set<VersionlessDependency> externalFirstLevel =
configuration
.getAllDependencies()
.withType(ExternalDependency.class)
.stream()
.map(factory::fromDependency)
.flatMap(Collection::stream)
.collect(Collectors.toSet());
@Var Set<ResolvedDependency> allModuleDependencies = null;
if (externalDependenciesExtension.versionedExportedDepsEnabled()) {
ResolvedConfiguration resolvedConfiguration = configuration.getResolvedConfiguration();
if (resolvedConfiguration.hasError()) {
// Throw failure if there was one during resolution
resolvedConfiguration.rethrowFailure();
}
Set<ResolvedDependency> firstLevelModuleDependencies =
resolvedConfiguration.getLenientConfiguration().getFirstLevelModuleDependencies();
allModuleDependencies =
resolvedConfiguration.getLenientConfiguration().getAllModuleDependencies();
// Infer first level project deps from the resolved graph and add to the projectFirstLevel
// list. This can happen if there are resolution rules which substitute a direct external
// dep with a project dep.
Set<String> directProjectDeps =
firstLevelModuleDependencies
.stream()
.map(DependencyUtils::filterProjectDeps)
.flatMap(Collection::stream)
.collect(Collectors.toSet());
projectFirstLevel.addAll(directProjectDeps);
// Infer transitive project deps of an external dependency from the resolved graph and add
// to the projectFirstLevel list. This can happen if there are resolution rules which
// substitute a transitive external dep with a project dep.
Set<String> transitiveProjectDeps =
allModuleDependencies
.stream()
.filter(DependencyUtils::isExternal)
.map(ResolvedDependency::getChildren)
.flatMap(Collection::stream)
.distinct()
.map(DependencyUtils::filterProjectDeps)
.flatMap(Collection::stream)
.collect(Collectors.toSet());
projectFirstLevel.addAll(transitiveProjectDeps);
Set<VersionlessDependency> firstLevelExternal =
firstLevelModuleDependencies
.stream()
.map(DependencyFactory::fromDependency)
.flatMap(Collection::stream)
.collect(Collectors.toSet());
externalFirstLevel.addAll(firstLevelExternal);
}
extractConfigurationImpl(configuration, projectFirstLevel, externalFirstLevel);
if (externalDependenciesExtension.versionedExportedDepsEnabled()) {
Preconditions.checkNotNull(allModuleDependencies);
allModuleDependencies.forEach(
rDep -> {
// Get all child deps
Set<OExternalDependency> childEDeps =
DependencyFactory.childrenFromDependency(rDep)
.stream()
.map(allExternal::get)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
// Update all matching external deps with this child deps
DependencyFactory.fromDependency(rDep)
.stream()
.map(allExternal::get)
.filter(Objects::nonNull)
.forEach(eDep -> eDep.addDeps(childEDeps));
// Add all child deps as first level deps if there are no self artifacts;
if (rDep.getModuleArtifacts().size() == 0) {
childEDeps.forEach(i -> firstLevelExternal.put(i.getVersionless(), i));
}
});
// Add exclude rule to the external dependency.
configuration
.getAllDependencies()
.stream()
.filter(dependency -> dependency instanceof ExternalDependency)
.map(dependency -> (ExternalDependency) dependency)
.forEach(
dependency -> {
Set<VersionlessDependency> vDeps = factory.fromDependency(dependency);
vDeps.forEach(
vDep -> {
OExternalDependency eDep = allExternal.getOrDefault(vDep, null);
if (eDep != null) {
eDep.addExcludeRules(dependency.getExcludeRules());
}
});
});
}
// Mark first level external deps as same in the object
firstLevelExternal.values().forEach(external -> external.updateFirstLevel(true));
}