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); }
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(); }
@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 static Provisioner fromProject(Project project) { Objects.requireNonNull(project); return (withTransitives, mavenCoords) -> { try { Dependency[] deps = mavenCoords.stream() .map(project.getBuildscript().getDependencies()::create) .toArray(Dependency[]::new); Configuration config = project.getRootProject().getBuildscript().getConfigurations().detachedConfiguration(deps); config.setDescription(mavenCoords.toString()); config.setTransitive(withTransitives); return config.resolve(); } catch (Exception e) { logger.log(Level.SEVERE, StringPrinter.buildStringFromLines("You probably need to add a repository containing the '" + mavenCoords + "' artifact in the 'build.gradle' of your root project.", "E.g.: 'buildscript { repositories { mavenCentral() }}'", "Note that included buildscripts (using 'apply from') do not share their buildscript repositories with the underlying project.", "You have to specify the missing repository explicitly in the buildscript of the root project."), e); throw e; } }; }
/** * 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); } }; }); }
/** * Creates a new configuration and passes it to the given {@code configurer}. The given {@code dependencies} * are added to the configuration. * * @param configurer the configurer * @param dependencies the dependencies * @return the new configuration */ Configuration newConfiguration(ConfigurationConfigurer configurer, Dependency... dependencies) { Configuration configuration = this.delegate.detachedConfiguration(dependencies); if (configurer != null) { configurer.configure(configuration); } this.configurations.add(configuration); return configuration; }
@Override public ModelSource2 resolveModel(String groupId, String artifactId, String version) throws UnresolvableModelException { String notation = groupId + ":" + artifactId + ":" + version + "@pom"; org.gradle.api.artifacts.Dependency dependency = project.getDependencies().create(notation); Configuration configuration = project.getConfigurations().detachedConfiguration(dependency); try { File file = configuration.getFiles().iterator().next(); return new SimpleModelSource(new FileInputStream(file)); } catch (Exception e) { throw new UnresolvableModelException(e, groupId, artifactId, version); } }
protected Optional<String> getPayaraMicroPath(String version) { DependencyHandler dependencyHandler = project.getDependencies(); Dependency dependency = dependencyHandler.create(MICRO_GROUPID + ":" + MICRO_ARTIFACTID + ":" + version); return project.getConfigurations() .detachedConfiguration(dependency) .getResolvedConfiguration() .getFiles() .stream() .findAny() .map(File::getAbsolutePath); }
private FileCollection resolveWorker() { Dependency shim = project.getDependencies().create("org.projectodd.shimdandy:shimdandy-api:" + SHIMDANDY_VERSION); return project.getConfigurations().detachedConfiguration(shim); }
@Override public InputStream getInputStream() throws Exception { // create a temporary configuration to resolve the file Configuration conf = project.getConfigurations().detachedConfiguration( project.getDependencies().create(dependencyNotation)); ResolvedArtifact artifactId = conf.getResolvedConfiguration().getResolvedArtifacts().iterator().next(); logger.info("Selected recommendation source " + artifactId.getId() + ", you requested " + dependencyNotation); return new FileInputStream(artifactId.getFile()); } };
@Override Set<File> getFilesOnConfiguration() { List<Dependency> rawPomDependencies = new ArrayList<>(); for(org.gradle.api.artifacts.Dependency dependency: configuration.getDependencies()) { rawPomDependencies.add(project.getDependencies().create(dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion() + "@pom")); } return project.getConfigurations().detachedConfiguration( rawPomDependencies.toArray(new org.gradle.api.artifacts.Dependency[0])).resolve(); } }
Configuration detachedConfiguration = _project.getConfigurations().detachedConfiguration(); detachedConfiguration.getDependencies().add(_project.getDependencies().create("org.gosu-lang.gosu:gosu-doc:" + gosuCoreApiRawVersion)); return detachedConfiguration;
/** * @param project the project on which we'll call {@link Project#javaexec(Action)}. * @param input the JavaExecable which we'll take as input and call run() on. * @param settings any extra settings you'd like to set on the JavaExec (e.g. heap) * @return the JavaExecable after it has had run() called. */ public static <T extends JavaExecable> T exec(Project project, T input, Action<JavaExecSpec> settings) throws Throwable { // copy the classpath from the project's buildscript (and its parents) List<FileCollection> classpaths = TreeStream.toParent(ProjectPlugin.treeDef(), project) .map(p -> p.getBuildscript().getConfigurations().getByName(BUILDSCRIPT_CLASSPATH)) .collect(Collectors.toList()); // add the gradleApi, workaround from https://discuss.gradle.org/t/gradle-doesnt-add-the-same-dependencies-to-classpath-when-applying-plugins/9759/6?u=ned_twigg classpaths.add(project.getConfigurations().detachedConfiguration(project.getDependencies().gradleApi())); // add stuff from the local classloader too, to fix testkit's classpath classpaths.add(project.files(JavaExecableImp.fromLocalClassloader())); // run it return JavaExecableImp.execInternal(input, project.files(classpaths), settings, execSpec -> JavaExecWinFriendly.javaExec(project, execSpec)); }
@Override protected FileSignature calculateState() throws Exception { Set<File> files = new LinkedHashSet<>(); for (Object o : projConfigMaven) { if (o instanceof Project) { Project project = (Project) o; Jar jar = taskFor(project); files.add(jar.getArchivePath()); files.addAll(project.getConfigurations().getByName(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME).resolve()); } else if (o instanceof Configuration) { Configuration config = (Configuration) o; files.addAll(config.resolve()); } else if (o instanceof String) { String mavenCoord = (String) o; Dependency dep = setupTask.getProject().getDependencies().create(mavenCoord); files.addAll(setupTask.getProject().getConfigurations() .detachedConfiguration(dep) .setDescription(mavenCoord) .setTransitive(false) .resolve()); } else { throw Unhandled.classException(o); } } return FileSignature.signAsList(files); }
private FileCollection resolveShim() { Dependency shimImpl = project.getDependencies().create("org.projectodd.shimdandy:shimdandy-impl:" + SHIMDANDY_VERSION); Dependency tools = project.getDependencies().create("io.github.gradle-clojure:gradle-clojure-tools:" + GRADLE_CLOJURE_VERSION); Dependency nrepl = project.getDependencies().create("org.clojure:tools.nrepl:" + NREPL_VERSION); return project.getConfigurations().detachedConfiguration(shimImpl, tools, nrepl).setTransitive(false); }
private Set<ResolvedDependency> doResolve(final Collection<ArtifactSpec> deps) { final Configuration config = this.project.getConfigurations().detachedConfiguration(); final DependencySet dependencySet = config.getDependencies(); deps.forEach(spec -> { final DefaultExternalModuleDependency d = new DefaultExternalModuleDependency(spec.groupId(), spec.artifactId(), spec.version()); final DefaultDependencyArtifact da = new DefaultDependencyArtifact(spec.artifactId(), spec.type(), spec.type(), spec.classifier(), null); d.addArtifact(da); d.getExcludeRules().add(new DefaultExcludeRule()); dependencySet.add(d); }); return config.getResolvedConfiguration().getFirstLevelModuleDependencies(); }
private Configuration createTemporaryConfiguration(Dependency dependency, String artifactLabel) { Configuration config = configurations.detachedConfiguration( dependency ); //parentConfiguration.ifPresent( c -> config.setExtendsFrom( Collections.singletonList( c ) ) ); config.setTransitive( false ); config.setVisible( false ); config.setDescription( "Generated configuration to resolve '" + artifactLabel + "' on behalf of the WildFly Provisioning plugin" ); //This next line actually resolves it (Attempts to download dependencies): final ResolvedConfiguration resolvedConfiguration = config.getResolvedConfiguration(); if ( resolvedConfiguration.hasError() ) { //In case of error, user is likely not having the JBoss Nexus repository enabled. //Attempt configuration correction: if ( autoAddRepositories && repositoriesAutomaticallyAdded == false ) { repositoriesAutomaticallyAdded = true; addDefaultRepositories( artifactLabel ); //And retry: return createTemporaryConfiguration( dependency, artifactLabel ); } else { resolvedConfiguration.rethrowFailure(); } } return config; }
@Override public FileCollection createDelegate() { checkRequiredSettings(project, hydraSettings); String scalaVersion = getScalaVersion(classpath); Configuration hydraConfiguration = project.getConfigurations().detachedConfiguration( new DefaultExternalModuleDependency("com.triplequote", "hydra_" + scalaVersion, hydraSettings.getVersion()) ); hydraConfiguration.exclude(excludeProperties("org.scala-lang", "scala-reflect")); hydraConfiguration.exclude(excludeProperties("com.triplequote", "scala-library")); LOGGER.debug("Hydra version: {}. Inferred Scala classpath: {}", hydraSettings.getVersion(), hydraConfiguration.getFiles()); Configuration hydraDashboardConfiguration = project.getConfigurations().getByName(HydraBasePlugin.HYDRA_DASHBOARD_CONFIGURATION); if (hydraDashboardConfiguration.getDependencies().isEmpty()) { hydraDashboardConfiguration.getDependencies().add( new DefaultExternalModuleDependency("com.triplequote", "dashboard-client_2.12", hydraSettings.getMetricsServiceVersion()) ); } return hydraConfiguration; }