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 Configuration createBootArchivesConfiguration(Project project) { Configuration bootArchives = project.getConfigurations().create( BOOT_ARCHIVES_CONFIGURATION_NAME); bootArchives.setDescription("Configuration for Spring Boot archive artifacts."); return bootArchives; }
@Nullable public static Configuration useful(@Nullable Configuration configuration) { if (configuration != null && configuration.isCanBeResolved()) { return configuration; } return 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; }
public void setupBuckBinary() { OkBuckExtension okbuckExt = ProjectUtil.getOkBuckExtension(rootProject); // Create dependency cache for buck binary if needed if (okbuckExt.buckBinary != null) { Configuration buckConfig = rootProject.getConfigurations().maybeCreate(BUCK_BINARY_CONFIGURATION); rootProject .getRepositories() .maven(mavenArtifactRepository -> mavenArtifactRepository.setUrl(JITPACK_URL)); rootProject.getDependencies().add(BUCK_BINARY_CONFIGURATION, okbuckExt.buckBinary); Set<File> resolvedFiles = buckConfig.getResolvedConfiguration().getFiles(); Preconditions.checkArgument(resolvedFiles.size() == 1); realBuckBinaryPath = resolvedFiles.iterator().next().toPath(); } }
@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); }
@Nullable public static Configuration useful(String configuration, Project project) { try { Configuration config = project.getConfigurations().getByName(configuration); return useful(config); } catch (UnknownConfigurationException ignored) { return null; } }
@SuppressWarnings("ResultOfMethodCallIgnored") public void setupGroovyHome() { Configuration groovyConfig = rootProject.getConfigurations().maybeCreate(GROOVY_DEPS_CONFIG); rootProject .getDependencies() .add(GROOVY_DEPS_CONFIG, "org.codehaus.groovy:groovy:" + groovyVersion); dependencies = new DependencyCache(rootProject, ProjectUtil.getDependencyManager(rootProject)) .build(groovyConfig); }
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)); }
DependencySet dependencies = configuration.getAllDependencies(); String processorsUID = dependencies .stream() .map( dep -> { if (dep.getVersion() == null || dep.getVersion().length() == 0) { return String.format("%s-%s", dep.getGroup(), dep.getName()); } else { return String.format( "%s-%s-%s", dep.getGroup(), dep.getName(), dep.getVersion()); .collect(Collectors.joining("-")); if (dependencies.size() > 1) { .stream() .filter( dep -> dep.getGroup() != null && dep.getGroup().equals(AnnotationProcessorCache.AUTO_VALUE_GROUP) && dep.getName().equals(AnnotationProcessorCache.AUTO_VALUE_NAME)) .map( dep -> String.format("%s-%s-%s", dep.getGroup(), dep.getName(), dep.getVersion())) .findAny();
public Set<File> classpath() { SourceSet sourceSet = sourceSet(project); // conf & public Set<File> cp = new LinkedHashSet<>(sourceSet.getResources().getSrcDirs()); // classes/main, resources/main + jars cp.addAll(sourceSet.getRuntimeClasspath().getFiles()); // provided? Configuration provided = project.getConfigurations().findByName("provided"); if (provided != null) { cp.addAll(provided.getFiles()); } return cp; }
@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(); }
public Scope build() { Configuration useful = DependencyUtils.useful(configuration); String key = useful != null ? useful.getName() : "--none--"; return ProjectCache.getScopeCache(project) .computeIfAbsent( key, t -> new Scope( project, useful, sourceDirs, javaResourceDirs, compilerOptions, depCache)); } }
/** * Checks if the configuration has any empty annotation processors. * * @param project project on which the configuration is defined. * @param configuration Configuration which is used to query the deps. * @return A boolean whether the configuration has any empty annotation processors. */ public boolean hasEmptyAnnotationProcessors(Project project, Configuration configuration) { Map<Set<Dependency>, Scope> depToScope = createProcessorScopes(project, configuration.getAllDependencies(), false); return depToScope .values() .stream() .anyMatch(scope -> scope.getAnnotationProcessors().isEmpty()); }
private Set<ExternalDependency> resolved(Collection<ExternalDependency> externalDependencies) { Configuration detached = project .getConfigurations() .detachedConfiguration( externalDependencies .stream() .map(ExternalDependency::getAsGradleDependency) .toArray(Dependency[]::new)); return DependencyUtils.resolveExternal( project, detached, externalDependenciesExtension, jetifierExtension); }
@Nullable private Configuration getConfigurationFromVariant(@Nullable BaseVariant variant) { @Var Configuration configuration = null; if (isKapt) { configuration = getProject() .getConfigurations() .getByName("kapt" + StringUtils.capitalize(getBaseVariant().getName())); } else if (variant != null) { configuration = variant.getAnnotationProcessorConfiguration(); } return configuration; }
@SuppressWarnings("ResultOfMethodCallIgnored") public Set<ExternalDependency> setupScalaHome(String scalaVersion) { Configuration scalaConfig = rootProject.getConfigurations().maybeCreate(SCALA_DEPS_CONFIG); rootProject .getDependencies() .add(SCALA_DEPS_CONFIG, "org.scala-lang:scala-compiler:" + scalaVersion); dependencies = new DependencyCache(rootProject, ProjectUtil.getDependencyManager(rootProject)) .build(scalaConfig); return dependencies; }
public DependencyCache getLintDepsCache() { if (lintDepCache == null) { lintDepCache = new DependencyCache(project, ProjectUtil.getDependencyManager(project)); dependencies = lintDepCache.build( project.getRootProject().getConfigurations().getByName(LINT_DEPS_CONFIG)); } return lintDepCache; }
@SuppressWarnings("ResultOfMethodCallIgnored") public void setupKotlinHome(String kotlinVersion) { this.kotlinHomeEnabled = true; this.kotlinVersion = kotlinVersion; Configuration kotlinConfig = project.getConfigurations().maybeCreate(KOTLIN_DEPS_CONFIG); DependencyHandler handler = project.getDependencies(); kotlinModules .stream() .map(module -> String.format("%s:%s:%s", KOTLIN_GROUP, module, kotlinVersion)) .forEach(dependency -> handler.add(KOTLIN_DEPS_CONFIG, dependency)); dependencies = new DependencyCache(project, ProjectUtil.getDependencyManager(project)).build(kotlinConfig); }
public void fetchManifestMergerDeps() { Configuration manifestMergerConfiguration = rootProject.getConfigurations().maybeCreate(CONFIGURATION_MANIFEST_MERGER); rootProject .getDependencies() .add( CONFIGURATION_MANIFEST_MERGER, MANIFEST_MERGER_GROUP + ":" + MANIFEST_MERGER_MODULE + ":" + ProjectUtil.findVersionInClasspath( rootProject, MANIFEST_MERGER_GROUP, MANIFEST_MERGER_MODULE)); dependencies = ImmutableSet.copyOf( new DependencyCache(rootProject, ProjectUtil.getDependencyManager(rootProject)) .build(manifestMergerConfiguration)); }