@Nullable public static String findVersionInClasspath(Project project, String group, String module) { return project .getBuildscript() .getConfigurations() .getByName("classpath") .getIncoming() .getArtifacts() .getArtifacts() .stream() .flatMap( artifactResult -> artifactResult.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier ? Stream.of( (ModuleComponentIdentifier) artifactResult.getId().getComponentIdentifier()) : Stream.empty()) .filter( identifier -> (group.equals(identifier.getGroup()) && module.equals(identifier.getModule()))) .findFirst() .map(ModuleComponentIdentifier::getVersion) .orElse(null); }
private Set<String> getCompileArtifactsForAgp2x() { Set<String> compileLibs = new HashSet<>(); Configuration configuration = project.getConfigurations().getByName("compile"); if (configuration.isCanBeResolved()) { ResolvableDependencies incoming = configuration.getIncoming(); ResolutionResult resolutionResult = incoming.getResolutionResult(); Set<ResolvedComponentResult> components = resolutionResult.getAllComponents(); for (ResolvedComponentResult result : components) { ModuleVersionIdentifier identifier = result.getModuleVersion(); if (identifier != null && !"unspecified".equals(identifier.getVersion())) { compileLibs.add( String.join(":", identifier.getGroup(), identifier.getName(), identifier.getVersion())); } } } return compileLibs; }
Set<ResolvedArtifactResult> consumableArtifacts = configuration .getIncoming() .getArtifacts() .getArtifacts()
private static Set<ResolvedArtifactResult> getArtifacts( Configuration configuration, String value, Spec<ComponentIdentifier> filter) { return configuration .getIncoming() .artifactView( config -> { config.attributes( container -> container.attribute(Attribute.of("artifactType", String.class), value)); config.componentFilter(filter); }) .getArtifacts() .getArtifacts(); }
private void unregisterUnresolvedDependenciesAnalyzer(Project project) { UnresolvedDependenciesAnalyzer unresolvedDependenciesAnalyzer = new UnresolvedDependenciesAnalyzer(); project.getConfigurations().all((configuration) -> { ResolvableDependencies incoming = configuration.getIncoming(); incoming.afterResolve((resolvableDependencies) -> { if (incoming.equals(resolvableDependencies)) { unresolvedDependenciesAnalyzer.analyze(configuration .getResolvedConfiguration().getLenientConfiguration() .getUnresolvedModuleDependencies()); } }); }); project.getGradle().buildFinished( (buildResult) -> unresolvedDependenciesAnalyzer.buildFinished(project)); }
@InputFiles @Classpath FileCollection getJarDependencies() { //Thanks to Xavier Durcrohet for this //https://android.googlesource.com/platform/tools/base/+/gradle_3.0.0/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/scope/VariantScopeImpl.java#1037 Action<AttributeContainer> attributes = container -> container.attribute(ARTIFACT_TYPE, AndroidArtifacts.ArtifactType.CLASSES.getType()); boolean lenientMode = false; return variant .getCompileConfiguration() .getIncoming() .artifactView( config -> { config.attributes(attributes); config.lenient(lenientMode); }) .getArtifacts() .getArtifactFiles(); }
@Override public void execute(final Configuration root) { root.getIncoming().beforeResolve(new Action<ResolvableDependencies>() { @Override public void execute(ResolvableDependencies resolvableDependencies) { if (dependencyManagementSettings.isOverriddenByDependencies()) { for (Configuration configuration : root.getHierarchy()) { processConfiguration(configuration); } } } }); }
private void addMinicondaInstallerDependency(final Project project, final MinicondaExtension miniconda) { configuration.getIncoming().beforeResolve(new Action<ResolvableDependencies>() { @Override public void execute(ResolvableDependencies resolvableDependencies) { // Allows custom minicondaInstaller ivy dependency override if (configuration.getDependencies().isEmpty()) { MinicondaInstaller installer = new MinicondaInstaller(os, miniconda); installer.addToDependencyHandler(project.getDependencies()); } } }); } }
private List<ModuleDependency> getVersionedModuleDependencies(Configuration configuration) { List<ModuleDependency> versionedModuleDependencies = new ArrayList<ModuleDependency>(); for (Dependency dependency : configuration.getIncoming().getDependencies()) { if (dependency instanceof ModuleDependency && dependency.getVersion() != null) { versionedModuleDependencies.add((ModuleDependency) dependency); } } return versionedModuleDependencies; }
/** * Collects configuration dependencies in post-order. * * @param configuration Gradle configuration to work with * @return set of resolved dependencies in post-order */ public static Set<ResolvedComponentResult> configurationPostOrderDependencies(Configuration configuration) { ResolvedComponentResult root = configuration.getIncoming().getResolutionResult().getRoot(); Set<ResolvedComponentResult> dependencies = new LinkedHashSet<>(); Set<ComponentIdentifier> seen = new HashSet<>(); postOrderDependencies(root, seen, dependencies); return dependencies; }
/** * Collects configuration dependencies in post-order. * * @param configuration Gradle configuration to work with * @return set of resolved dependencies in post-order */ public static Set<ResolvedComponentResult> configurationPostOrderDependencies(Configuration configuration) { ResolvedComponentResult root = configuration.getIncoming().getResolutionResult().getRoot(); Set<ResolvedComponentResult> dependencies = new LinkedHashSet<>(); Set<ComponentIdentifier> seen = new HashSet<>(); postOrderDependencies(root, seen, dependencies); return dependencies; }
static Set<String> getResolvedModuleIdentifiers(Project project) { return project.getConfigurations().stream() .filter(Configuration::isCanBeResolved) .flatMap(configuration -> { try { ResolutionResult resolutionResult = configuration.getIncoming().getResolutionResult(); return resolutionResult .getAllComponents() .stream() .map(result -> result.getId()) .filter(cid -> !cid.equals(resolutionResult.getRoot().getId())) // remove the project .filter(cid -> cid instanceof ModuleComponentIdentifier) .map(mcid -> ((ModuleComponentIdentifier) mcid).getModuleIdentifier()) .map(mid -> mid.getGroup() + ":" + mid.getName()); } catch (Exception e) { throw new RuntimeException(String.format("Error during resolution of the dependency graph of " + "configuration %s", configuration), e); } }) .collect(Collectors.toSet()); } }
/** * Configures the agent dependencies using the 'jacocoAnt' configuration. * Uses the version declared as a build script dependency if no other versions are specified. */ private void configureAgentDependencies(final String jacocoVersion) { final Configuration config = project.getConfigurations().getByName(AGENT_CONFIGURATION_NAME); config.getIncoming().beforeResolve(new Action<ResolvableDependencies>() { @Override public void execute(ResolvableDependencies resolvableDependencies) { if (config.getDependencies().isEmpty()) { config.getDependencies().add(project.getDependencies().create( "org.jacoco:org.jacoco.agent:" + jacocoVersion)); } } }); }
private Set<GradleLibrary> getLibrariesForFileDependencies(Configuration configuration, LibraryScope scope) { Set<GradleLibrary> libraries = new LinkedHashSet<GradleLibrary>(); for (Dependency dependency : configuration.getIncoming().getDependencies()) { if (dependency instanceof FileCollectionDependency) { FileCollectionDependency fileDependency = (FileCollectionDependency) dependency; for (File file : fileDependency.resolve()) { libraries.add(new GradleLibrary(fileDependency.getGroup(), file, scope)); } } else if (dependency instanceof ProjectDependency) { ProjectDependency projectDependency = (ProjectDependency) dependency; libraries.addAll(getLibrariesForFileDependencies(projectDependency.getProjectConfiguration(), scope)); } } return libraries; }
public ParallelWheelGenerationTask() { onlyIf(task -> { ByteArrayOutputStream stdOut = new ByteArrayOutputStream(); getProject().exec(execSpec -> { execSpec.setExecutable(getPythonDetails().getVirtualEnvInterpreter()); execSpec.args(getPythonDetails().getVirtualEnvironment().getPip(), "freeze", "--all"); execSpec.setStandardOutput(stdOut); }); Configuration requiredDependencies = getProject().getConfigurations() .getByName(CONFIGURATION_SETUP_REQS.getValue()); Set<String> setupRequiresDependencies = requiredDependencies.getIncoming().getDependencies().stream() .flatMap(it -> Stream.of(it.getName(), it.getName().replace("-", "_"))) .collect(Collectors.toSet()); Set<String> extraDependencies = Arrays.stream(stdOut.toString().trim().split(System.lineSeparator())) .filter(it -> it.contains("==")).map(it -> it.split("==")[0]) .filter(it -> !setupRequiresDependencies.contains(it)) .collect(Collectors.toSet()); if (!extraDependencies.isEmpty()) { logger.info("Extra dependencies found ({}). Skipping parallel wheel building.", extraDependencies); } return extraDependencies.isEmpty(); }); }
/** * Configures the classpath for Jacoco tasks using the 'jacocoAnt' configuration. * Uses the version declared as a build script dependency if no other versions are specified. */ private void configureTaskClasspathDefaults(final String jacocoVersion) { final Configuration config = project.getConfigurations().getByName(ANT_CONFIGURATION_NAME); config.getIncoming().beforeResolve(new Action<ResolvableDependencies>() { @Override public void execute(ResolvableDependencies resolvableDependencies) { if (config.getDependencies().isEmpty()) { config.getDependencies().add(project.getDependencies().create( "org.jacoco:org.jacoco.ant:" + jacocoVersion)); } } }); } }
public ParallelWheelGenerationTask() { onlyIf(task -> { ByteArrayOutputStream stdOut = new ByteArrayOutputStream(); getProject().exec(execSpec -> { execSpec.setExecutable(getPythonDetails().getVirtualEnvInterpreter()); execSpec.args(getPythonDetails().getVirtualEnvironment().getPip(), "freeze", "--all"); execSpec.setStandardOutput(stdOut); }); Configuration requiredDependencies = getProject().getConfigurations() .getByName(CONFIGURATION_SETUP_REQS.getValue()); Set<String> setupRequiresDependencies = requiredDependencies.getIncoming().getDependencies().stream() .flatMap(it -> Stream.of(it.getName(), it.getName().replace("-", "_"))) .collect(Collectors.toSet()); Set<String> extraDependencies = Arrays.stream(stdOut.toString().trim().split(System.lineSeparator())) .filter(it -> it.contains("==")).map(it -> it.split("==")[0]) .filter(it -> !setupRequiresDependencies.contains(it)) .collect(Collectors.toSet()); if (!extraDependencies.isEmpty()) { logger.info("Extra dependencies found ({}). Skipping parallel wheel building.", extraDependencies); } return extraDependencies.isEmpty(); }); }
configuration.getName(), this.project.getName()); configuration.getIncoming().beforeResolve(new Action<ResolvableDependencies>() { this.project, this.dependencyManagementContainer, configuration); configuration.getIncoming().beforeResolve(new ExclusionConfiguringAction(this.dependencyManagementSettings, this.dependencyManagementContainer, this.configurationContainer, configuration, this.exclusionResolver, new DependencyManagementConfigurationContainer.ConfigurationConfigurer() {
this.configurationConfigurer, allDependencies.toArray(new org.gradle.api.artifacts.Dependency[allDependencies.size()])); ResolutionResult resolutionResult = configurationCopy.getIncoming().getResolutionResult(); ResolvedComponentResult root = resolutionResult.getRoot(); final Set<DependencyCandidate> excludedDependencies = new HashSet<DependencyCandidate>();
private static DependencyOverwrites collectDependenciesToOverwrite(final Configuration compileClasspath, final Configuration testCompile, final XRepoConfiguration config, final Project project) { final Configuration groupDeps = dependenciesWithinProjectGroup(testCompile, project); debug(project, "Found {} dependencies with group {}", groupDeps.getAllDependencies().size(), project.getGroup()); useSuffixedVersions(groupDeps, config, project); final DependencyOverwrites result = new DependencyOverwrites(); compileClasspath.getIncoming().beforeResolve((deps) -> { groupDeps.getResolvedConfiguration().getLenientConfiguration().getAllModuleDependencies().forEach(dep -> { if (isInSameGroup(dep.getModuleGroup(), project)) { debug(project, "Found overwritten dependency {}:{}:{}", dep.getModuleGroup(), dep.getModuleName(), dep.getModuleVersion()); result.add(dep); } }); }); return result; }