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 public static Configuration useful(String configuration, Project project) { try { Configuration config = project.getConfigurations().getByName(configuration); return useful(config); } catch (UnknownConfigurationException ignored) { return null; } }
private Configuration createBootArchivesConfiguration(Project project) { Configuration bootArchives = project.getConfigurations().create( BOOT_ARCHIVES_CONFIGURATION_NAME); bootArchives.setDescription("Configuration for Spring Boot archive artifacts."); return bootArchives; }
public void fetchLintDeps(String version) { // Invalidate lint deps when versions change File lintVersionFile = project.file(LINT_VERSION_FILE); try { if (!lintVersionFile.exists() || !version.equals( new String(Files.readAllBytes(lintVersionFile.toPath()), StandardCharsets.UTF_8))) { FileUtils.deleteDirectory(lintVersionFile.getParentFile()); lintVersionFile.getParentFile().mkdirs(); Files.write(lintVersionFile.toPath(), Collections.singleton(version)); } } catch (Exception e) { throw new RuntimeException(e); } project.getConfigurations().maybeCreate(LINT_DEPS_CONFIG); project.getDependencies().add(LINT_DEPS_CONFIG, LINT_GROUP + ":" + LINT_MODULE + ":" + version); getLintDepsCache(); }
private Map<Set<Dependency>, Scope> createProcessorScopes( Project project, Set<Dependency> dependencies, boolean groupDependencies) { ImmutableMap.Builder<Set<Dependency>, Scope> currentBuilder = new ImmutableMap.Builder<>(); // Creates a scope using a detached configuration and the given dependency set. Function<Set<Dependency>, Scope> computeScope = depSet -> { Dependency[] depArray = depSet.toArray(new Dependency[0]); Configuration detached = project.getConfigurations().detachedConfiguration(depArray); return Scope.builder(project).configuration(detached).build(); }; if (groupDependencies) { // Creates one scope for all the dependencies if not // already present and adds it to the current builder. ImmutableSet<Dependency> dependencySet = ImmutableSet.copyOf(dependencies); Scope scope = dependencyToScopeMap.computeIfAbsent(dependencySet, computeScope); currentBuilder.put(dependencySet, scope); } else { // Creates one scope per dependency if not already // found and adds it to the current builder. dependencies.forEach( dependency -> { ImmutableSet<Dependency> dependencySet = ImmutableSet.of(dependency); Scope scope = dependencyToScopeMap.computeIfAbsent(dependencySet, computeScope); currentBuilder.put(dependencySet, scope); }); } return currentBuilder.build(); }
@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 setupJetifier(String version) { if (!version.equals(JetifierExtension.DEFAULT_JETIFIER_VERSION)) { LOG.warn( "Using jetifier version other than %s; This might result in problems with the tool", JetifierExtension.DEFAULT_JETIFIER_VERSION); } Configuration jetifierConfig = project.getConfigurations().maybeCreate(JETIFIER_DEPS_CONFIG); DependencyHandler handler = project.getDependencies(); JETIFIER_MODULES .stream() .map(module -> String.format("%s:%s:%s", JETIFIER_GROUP, module, version)) .forEach(dependency -> handler.add(JETIFIER_DEPS_CONFIG, dependency)); handler.add(JETIFIER_DEPS_CONFIG, COMMONS_CLI_DEP); dependencies = new DependencyCache(project, ProjectUtil.getDependencyManager(project)) .build(jetifierConfig); }
@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; }
@Nullable public static String getProguardJarPath(Project project) { String proguardVersion = ProjectUtil.findVersionInClasspath(project, PROGUARD_GROUP, PROGUARD_MODULE); Configuration proguardConfiguration = project .getConfigurations() .detachedConfiguration( new DefaultExternalModuleDependency( PROGUARD_GROUP, PROGUARD_MODULE, proguardVersion)); DependencyCache cache = new DependencyCache(project, ProjectUtil.getDependencyManager(project)); Set<ExternalDependency> dependencies = cache.build(proguardConfiguration); Optional<ExternalDependency> proguardDependency = dependencies .stream() .filter( dependency -> dependency.getGroup().equals(PROGUARD_GROUP) && dependency.getName().equals(PROGUARD_MODULE)) .findAny(); return proguardDependency.map(BuckRuleComposer::external).orElse(null); } }
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; }
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(); } }
public void download() { ImmutableSet.Builder<Configuration> runtimeDeps = ImmutableSet.builder(); Set<API> apisToDownload; Set<String> configuredApis = ProjectUtil.getOkBuckExtension(rootProject).getTestExtension().robolectricApis; if (configuredApis != null) { apisToDownload = configuredApis.stream().map(API::from).collect(Collectors.toSet()); } else { apisToDownload = EnumSet.allOf(API.class); } for (API api : apisToDownload) { Configuration runtimeApi = rootProject.getConfigurations().maybeCreate(ROBOLECTRIC_RUNTIME + "_" + api.name()); rootProject.getDependencies().add(runtimeApi.getName(), api.getCoordinates()); runtimeDeps.add(runtimeApi); } DependencyCache dependencyCache = new DependencyCache(rootProject, ProjectUtil.getDependencyManager(rootProject)); dependencies = runtimeDeps .build() .stream() .map(dependencyCache::build) .flatMap(Set::stream) .collect(com.uber.okbuck.core.util.MoreCollectors.toImmutableSet()); }
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; }
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; }
@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; }
@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); }
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)); }
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)); }
rootProject.getConfigurations().maybeCreate(TransformManager.CONFIGURATION_TRANSFORM); rootProject.getConfigurations().maybeCreate(FORCED_OKBUCK); cacheName -> rootBuckProject .getConfigurations() .maybeCreate(cacheName + "ExtraDepCache"))); .forEach( bp -> { bp.getConfigurations().maybeCreate(BUCK_LINT);
/** * Creates a Provisioner for the given repositories. * * The first time a project is created, there are ~7 seconds of configuration * which will go away for all subsequent runs. * * Every call to resolve will take about 1 second, even when all artifacts are resolved. */ private static Supplier<Provisioner> createLazyWithRepositories(Consumer<RepositoryHandler> repoConfig) { // Running this takes ~3 seconds the first time it is called. Probably because of classloading. return Suppliers.memoize(() -> { Project project = ProjectBuilder.builder().build(); repoConfig.accept(project.getRepositories()); return (withTransitives, mavenCoords) -> { Dependency[] deps = mavenCoords.stream() .map(project.getDependencies()::create) .toArray(Dependency[]::new); Configuration config = project.getConfigurations().detachedConfiguration(deps); config.setTransitive(withTransitives); config.setDescription(mavenCoords.toString()); try { return config.resolve(); } catch (ResolveException e) { /* Provide Maven coordinates in exception message instead of static string 'detachedConfiguration' */ throw new ResolveException(config.getDescription(), e); } }; }); }