public void addDartAndHensonDependenciesToVariantConfigurations(String dartVersionName) { DependencyHandler dependencies = project.getDependencies(); dependencies.add("implementation", format("com.f2prateek.dart:henson:%s", dartVersionName)); } }
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(); }
@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); }
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()); }
DependencyHandler dependencies = project.getDependencies();
@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)); }
/** * 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 {@code MavenPomResolver}. Properties from the given {@code project} will be used during resolution. * The given {@code configurationContainer} will be used to create configurations to resolve the poms. * * @param project the project * @param configurationContainer the configuration container */ public MavenPomResolver(Project project, DependencyManagementConfigurationContainer configurationContainer) { this.configurationContainer = configurationContainer; this.effectiveModelBuilder = new EffectiveModelBuilder(project, configurationContainer); this.dependencyHandler = project.getDependencies(); }
private FileModelSource resolveModel(String coordinates) { Dependency dependency = this.project.getDependencies().create(coordinates); Configuration configuration = this.configurationContainer.newConfiguration(dependency); return new FileModelSource(configuration.resolve().iterator().next()); }
@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); } }
private void addDependencies() { final DependencyHandler handler = this.project.getDependencies(); handler.add( "compile", this.ext.dependency( "boot" ) ); handler.add( "testCompile", this.ext.dependency( "testing" ) ); }
private void configureForSpotbugs(JavaPluginConvention javaPluginConvention) { lombokExtension.getConfig().put("lombok.extern.findbugs.addSuppressFBWarnings", "true"); CodeQualityExtension spotbugsExtension = (CodeQualityExtension) project.getExtensions().getByName("spotbugs"); javaPluginConvention.getSourceSets().all(sourceSet -> project.getDependencies().add( sourceSet.getCompileOnlyConfigurationName(), "com.github.spotbugs:spotbugs-annotations:" + spotbugsExtension.getToolVersion() )); }
private void updateJavaFXDependencies() { clearJavaFXDependencies(); JavaFXModule.getJavaFXModules(this.modules).forEach(javaFXModule -> { project.getDependencies().add("implementation", String.format("%s:%s:%s:%s", MAVEN_JAVAFX_ARTIFACT_GROUP_ID, javaFXModule.getArtifactName(), getVersion(), getPlatform().getClassifier())); }); }
private void addGosuRuntimeDependencies() { Set<ResolvedArtifact> buildScriptDeps = _project.getBuildscript().getConfigurations().getByName("classpath").getResolvedConfiguration().getResolvedArtifacts(); ResolvedArtifact gosuCore = GosuPlugin.getArtifactWithName("gosu-core", buildScriptDeps); ResolvedArtifact gosuCoreApi = GosuPlugin.getArtifactWithName("gosu-core-api", buildScriptDeps); //inject Gosu jar dependencies into the classpath of the project implementing this plugin _project.getDependencies().add("runtime", gosuCore.getModuleVersion().getId().toString()); _project.getDependencies().add("compile", gosuCoreApi.getModuleVersion().getId().toString()); }
@Override public void execute(ResolvableDependencies resolvableDependencies) { if (config.getDependencies().isEmpty()) { config.getDependencies().add(project.getDependencies().create( "org.jacoco:org.jacoco.agent:" + jacocoVersion)); } } });
public GradleArtifactFileResolver(Project project, boolean autoAddRepositories) { this.project = project; this.dependencies = project.getDependencies(); this.configurations = project.getConfigurations(); this.knownPublications = extractPublishingExtensions( project.getRootProject().getAllprojects() ); this.logger = project.getLogger(); this.autoAddRepositories = autoAddRepositories; }