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; } }; }
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 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; }
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; }
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)); }
@Override public void execute(Configuration files) { files.setVisible(false); files.setTransitive(true); files.setDescription("The Jacoco agent to use to get coverage data."); } });
private Configuration configureAgentDependencies(Project project, ScottPluginExtension extension) { Configuration agentConf = project.getConfigurations().create(AGENT_CONFIGURATION_NAME); agentConf.setVisible(false); agentConf.setTransitive(true); agentConf.setDescription("The Scott agent to use detailed failure reports and hassle free assertions for Java tests"); agentConf.defaultDependencies(dependencies -> dependencies.add(project.getDependencies().create("hu.advancedweb:scott:" + extension.getToolVersion())) ); return agentConf; }
@Test public void testGetResolvedArtifacts_returnArtifact() { Set<ResolvedArtifact> artifactSet = (Set<ResolvedArtifact>) mock(Set.class); ResolvedConfiguration resolvedConfiguration = mock(ResolvedConfiguration.class); when(resolvedConfiguration.getResolvedArtifacts()).thenReturn(artifactSet); Configuration configuration = mock(Configuration.class); when(configuration.getName()).thenReturn("compile"); when(configuration.isCanBeResolved()).thenReturn(true); when(configuration.getResolvedConfiguration()).thenReturn(resolvedConfiguration); assertThat(dependencyTask.getResolvedArtifacts(configuration), is(artifactSet)); }
protected void appendDependenciesOf(@Nonnull Configuration configuration, @Nonnull Collection<GolangDependency> to) { for (final Dependency dependency : configuration.getDependencies()) { final GolangDependency toAdd; if (dependency instanceof GolangDependency) { toAdd = (GolangDependency) dependency; } else { toAdd = new GolangDependency(dependency); } if (!to.contains(toAdd)) { to.add(toAdd); } } }
private Configuration addToolDependency(Project project) { Configuration config = project.getConfigurations().create("susel") .setVisible(false) .setDescription("Process and create metadata for all service providers."); config.defaultDependencies(dependencies -> dependencies.add(project.getDependencies().create("io.github.udaychandra.susel:tool:0.1.2"))); return config; }
private Configuration _addConfigurationJSCompile(Project project) { Configuration configuration = GradleUtil.addConfiguration( project, JS_COMPILE_CONFIGURATION_NAME); configuration.setDescription( "Configures additional JavaScript dependencies."); configuration.setVisible(false); return configuration; }
private void configureConfigurations( ConfigurationContainer configurationContainer) { Configuration provideCompileConfiguration = configurationContainer .create(PROVIDED_COMPILE_CONFIGURATION_NAME) .setVisible(false) .setDescription( "Additional compile classpath for libraries that should not be part of the FSM archive."); Configuration provideRuntimeConfiguration = configurationContainer .create(PROVIDED_RUNTIME_CONFIGURATION_NAME) .setVisible(false) .extendsFrom(provideCompileConfiguration) .setDescription( "Additional runtime classpath for libraries that should not be part of the FSM archive."); configurationContainer.getByName(JavaPlugin.COMPILE_CONFIGURATION_NAME) .extendsFrom(provideCompileConfiguration); configurationContainer.getByName(JavaPlugin.RUNTIME_CONFIGURATION_NAME) .extendsFrom(provideRuntimeConfiguration); }
@Override public void execute(Configuration configuration) { if (container.getExcludedConfigurations().contains(configuration.getName())) { return; } if (configuration.getState() == Configuration.State.UNRESOLVED) { Configuration toExtend = bom; if (!project.getRootProject().equals(project)) { toExtend = bom.copy(); toExtend.setVisible(false); project.getConfigurations().add(toExtend); } configuration.extendsFrom(toExtend); } else { logger.info("Configuration '" + configuration.getName() + "' has already been resolved and cannot be included for recommendation"); } } }
private static VersionNumber retrolambdaVersion(Configuration retrolambdaConfig) { retrolambdaConfig.resolve(); Dependency retrolambdaDep = retrolambdaConfig.getDependencies().iterator().next(); if (retrolambdaDep.getVersion() == null) { // Don't know version return null; } return VersionNumber.parse(retrolambdaDep.getVersion()); }
/** * 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); } }; }); }
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 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; }
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)); } }
private void configureToolsConfigurations(Project project) { Configuration tools = project.getConfigurations().create(TOOLS_CONFIGURATION_NAME); tools.defaultDependencies(deps -> { deps.add(project.getDependencies().create("io.github.gradle-clojure:gradle-clojure-tools:" + getVersion())); }); // TODO does this JAR get included via shadow or application plugins? project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> { project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName()).extendsFrom(tools); project.getConfigurations().getByName(sourceSet.getRuntimeClasspathConfigurationName()).extendsFrom(tools); }); }
private void configureDefaultJavaccDependency(final Project project, Configuration configuration) { configuration.defaultDependencies(new Action<DependencySet>() { @Override public void execute(DependencySet dependencies) { dependencies.add(project.getDependencies().create("net.java.dev.javacc:javacc:6.1.2")); } }); }