@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 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 void prepareConfigurations(Project project) { ConfigurationContainer confs = project.getConfigurations(); azureTestCompileConf = confs.create(AZURE_TEST_COMPILE_CONF, (Configuration c) -> { c.extendsFrom(confs.getByName("testCompile")); }); azureRuntimeConf = confs.create(AZURE_TEST_RUNTIME_CONF, (Configuration c) -> { c.extendsFrom(confs.getByName("testRuntime")); }); }
/** * @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)); }
public static Configuration cqPackageConfiguration(Project project) { val conf = project.getConfigurations().findByName(CqPackagePlugin.CQ_PACKAGE); if (conf == null) { createCqPackageConf(project); return project.getConfigurations().getByName(CqPackagePlugin.CQ_PACKAGE); } return conf; }
protected Configuration getOrCreateConfiguration(String name) { Configuration configuration = project.getConfigurations().findByName( name ); if ( configuration == null ) { configuration = project.getConfigurations().create( name ); } return configuration; } }
private static void createCqPackageConf(Project project) { LOG.debug("Creating configuration: {}", CqPackagePlugin.CQ_PACKAGE); val cqPackageConf = project.getConfigurations().create(CqPackagePlugin.CQ_PACKAGE); // attach to "runtime", but don't insist that it have to be there first (or will ever be there) project.getConfigurations().withType(Configuration.class, conf -> { if (conf.getName().equals("runtime")) { LOG.debug("Making {} extend from {}", CqPackagePlugin.CQ_PACKAGE, conf.getName()); cqPackageConf.extendsFrom(conf); } }); }
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 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 protected void configureTaskDefaults(SpotBugsTask task, String baseName) { task.setPluginClasspath(project.getConfigurations().getAt("spotbugsPlugins")); Configuration configuration = project.getConfigurations().getAt("spotbugs"); configureDefaultDependencies(configuration); configureTaskConventionMapping(configuration, task); configureReportsConventionMapping(task, baseName); }
@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); }
protected Configuration getOrCreateConfiguration(String name) { Configuration configuration = project.getConfigurations().findByName( name ); if ( configuration == null ) { configuration = project.getConfigurations().create( name ); } return configuration; } }
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(); }
private void addEtaExtensionForConfigurations() { project.getConfigurations().all(this::populateEtaConfiguration); }
@Override protected void configureTaskDefaults(FindBugs task, String baseName) { task.setPluginClasspath(project.getConfigurations().getAt("findbugsPlugins")); Configuration configuration = project.getConfigurations().getAt(getConfigurationName()); configureTaskConventionMapping(configuration, task); configureReportsConventionMapping(task, baseName); }
@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; }
private void defineConfiguration() { // Defer creation and resolution of configuration until required. Short-circuit when script does not require classpath if (configContainer == null) { configContainer = dependencyResolutionServices.getConfigurationContainer(); } if (classpathConfiguration == null) { classpathConfiguration = configContainer.create(CLASSPATH_CONFIGURATION); } }