@Override public Iterable<Dependency> getRunsupportClasspathDependencies(String playVersion, String scalaCompatibilityVersion) { ImmutableList.Builder<Dependency> listBuilder = ImmutableList.builder(); String runsupportPlayVersion = playVersion; boolean transitive = true; // use run-support from 2.3.7 for versions before Play 2.3.7 if (VersionNumber.parse(playVersion).compareTo(MINIMUM_PLAY_VERSION_WITH_RUN_SUPPORT) < 0) { runsupportPlayVersion = "2.3.7"; transitive = false; } DefaultExternalModuleDependency runSupportDependency = new DefaultExternalModuleDependency("com.typesafe.play", RUN_SUPPORT_PLAY_MODULE + "_" + scalaCompatibilityVersion, runsupportPlayVersion); runSupportDependency.setTransitive(transitive); listBuilder.add(runSupportDependency); String name = scalaCompatibilityVersion.equals("2.10") ? "io" : ("io_" + scalaCompatibilityVersion); DefaultExternalModuleDependency dependency = new DefaultExternalModuleDependency("org.scala-sbt", name, getIOSupportDependencyVersion(), "runtime"); dependency.setTransitive(false); listBuilder.add(dependency); return listBuilder.build(); }
private Set<String> getBundleDependencies(Configuration compileClasspath, Set<? extends DependencyResult> bundleDependencies) { Set<String> bundleSets = new HashSet<>(); for (DependencyResult dependencyResult : bundleDependencies) { bundleSets.add(dependencyResult.toString()); } for (Dependency dependency : compileClasspath.getAllDependencies()) { if (dependency instanceof DefaultExternalModuleDependency) { DefaultExternalModuleDependency externalModuleDependency = (DefaultExternalModuleDependency)dependency; if (!((DefaultExternalModuleDependency)dependency).getArtifacts().isEmpty()) { if (StringUtils.equalsIgnoreCase("awb", ((DefaultExternalModuleDependency)dependency).getArtifacts() .iterator().next().getType())) { bundleSets.add( dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion()); } } } } return bundleSets; }
@Override public void apply(Project project) { EkstaziExtension extension = project.getExtensions().create(EKSTAZI, EkstaziExtension.class); project.afterEvaluate(p -> { Configuration ekstazi = project.getConfigurations().detachedConfiguration( new DefaultExternalModuleDependency(EKSTAZI_GROUP, EKSTAZI_NAME, extension.getVersion()) ); p.getTasks().withType(Test.class).forEach(task -> { task.dependsOn(ekstazi); System.out.println( extension.toString()); task.jvmArgs( String.format("-javaagent:%s=root.dir=%s,%s", ekstazi.getFiles().iterator().next().getAbsolutePath(), task.getProject().getBuildDir().getAbsolutePath() + File.separator + ".ekstazi" + File.separator + task.getName(), extension.toString()) ); } ); } ); }
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(); }
/** * Searches the specified class path for a 'scala-library' Jar, and returns a class path * containing a corresponding (same version) 'scala-compiler' Jar and its dependencies. * * <p>The returned class path may be empty, or may fail to resolve when asked for its contents. * * @param classpath a class path containing a 'scala-library' Jar * @return a class path containing a corresponding 'scala-compiler' Jar and its dependencies */ public FileCollection inferScalaClasspath(final Iterable<File> classpath) { // alternatively, we could return project.files(Runnable) // would differ in the following ways: 1. live (not sure if we want live here) 2. no autowiring (probably want autowiring here) return new LazilyInitializedFileCollection() { @Override public String getDisplayName() { return "Scala runtime classpath"; } @Override public FileCollection createDelegate() { if (project.getRepositories().isEmpty()) { throw new GradleException(String.format("Cannot infer Scala class path because no repository is declared in %s", project)); } File scalaLibraryJar = findScalaJar(classpath, "library"); if (scalaLibraryJar == null) { throw new GradleException(String.format("Cannot infer Scala class path because no Scala library Jar was found. " + "Does %s declare dependency to scala-library? Searched classpath: %s.", project, classpath)); } String scalaVersion = getScalaVersion(scalaLibraryJar); if (scalaVersion == null) { throw new AssertionError(String.format("Unexpectedly failed to parse version of Scala Jar file: %s in %s", scalaLibraryJar, project)); } return project.getConfigurations().detachedConfiguration(new DefaultExternalModuleDependency("org.scala-lang", "scala-compiler", scalaVersion)); } // let's override this so that delegate isn't created at autowiring time (which would mean on every build) @Override public void visitDependencies(TaskDependencyResolveContext context) { if (classpath instanceof Buildable) { context.add(classpath); } } }; }
public static NotationParser<Object, Dependency> parser(Instantiator instantiator, DefaultProjectDependencyFactory dependencyFactory, ClassPathRegistry classPathRegistry, FileLookup fileLookup, RuntimeShadedJarFactory runtimeShadedJarFactory, CurrentGradleInstallation currentGradleInstallation) { return NotationParserBuilder .toType(Dependency.class) .fromCharSequence(new DependencyStringNotationConverter<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class)) .converter(new DependencyMapNotationConverter<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class)) .fromType(FileCollection.class, new DependencyFilesNotationConverter(instantiator)) .fromType(Project.class, new DependencyProjectNotationConverter(dependencyFactory)) .fromType(DependencyFactory.ClassPathNotation.class, new DependencyClassPathNotationConverter(instantiator, classPathRegistry, fileLookup.getFileResolver(), runtimeShadedJarFactory, currentGradleInstallation)) .invalidNotationMessage("Comprehensive documentation on dependency notations is available in DSL reference for DependencyHandler type.") .toComposite(); }
private Collection<ResolvedArtifact> doResolve(final Collection<ArtifactSpec> deps, boolean transitive) { final Configuration config = this.project.getConfigurations().detachedConfiguration().setTransitive(transitive); final DependencySet dependencySet = config.getDependencies(); deps.forEach(spec -> { if (projects.containsKey(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version())) { dependencySet.add(new DefaultProjectDependency((ProjectInternal) projects.get(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version()), new DefaultProjectAccessListener(), false)); } else { 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); dependencySet.add(d); } }); if (transitive) { return config .getResolvedConfiguration() .getResolvedArtifacts(); } return config .getResolvedConfiguration() .getFirstLevelModuleDependencies() .stream() .map(dep -> dep.getModuleArtifacts()) .flatMap(artifacts -> artifacts.stream()) .collect(Collectors.toList()); }
/** * Searches the specified class path for a 'scala-library' Jar, and returns a class path * containing a corresponding (same version) 'scala-compiler' Jar and its dependencies. * * <p>If the (deprecated) 'scalaTools' configuration is explicitly configured, no repository * is declared for the project, no 'scala-library' Jar is found on the specified class path, * or its version cannot be determined, a class path with the contents of the 'scalaTools' * configuration is returned. * * <p>The returned class path may be empty, or may fail to resolve when asked for its contents. * * @param classpath a class path containing a 'scala-library' Jar * @return a class path containing a corresponding 'scala-compiler' Jar and its dependencies */ public FileCollection inferScalaClasspath(final Iterable<File> classpath) { // alternatively, we could return project.files(Runnable) // would differ in the following ways: 1. live (not sure if we want live here) 2. no autowiring (probably want autowiring here) return new LazilyInitializedFileCollection() { @Override public FileCollection createDelegate() { if (project.getRepositories().isEmpty()) { throw new GradleException(String.format("Cannot infer Scala class path because no repository is declared in %s", project)); } File scalaLibraryJar = findScalaJar(classpath, "library"); if (scalaLibraryJar == null) { throw new GradleException(String.format("Cannot infer Scala class path because no Scala library Jar was found. " + "Does %s declare dependency to scala-library? Searched classpath: %s.", project, classpath)); } String scalaVersion = getScalaVersion(scalaLibraryJar); if (scalaVersion == null) { throw new AssertionError(String.format("Unexpectedly failed to parse version of Scala Jar file: %s in %s", scalaLibraryJar, project)); } return project.getConfigurations().detachedConfiguration( new DefaultExternalModuleDependency("org.scala-lang", "scala-compiler", scalaVersion)); } // let's override this so that delegate isn't created at autowiring time (which would mean on every build) @Override public TaskDependency getBuildDependencies() { if (classpath instanceof Buildable) { return ((Buildable) classpath).getBuildDependencies(); } return new TaskDependency() { public Set<? extends Task> getDependencies(Task task) { return Collections.emptySet(); } }; } }; }
public static NotationParser<Object, Dependency> parser(Instantiator instantiator, DefaultProjectDependencyFactory dependencyFactory, ClassPathRegistry classPathRegistry, FileLookup fileLookup) { return NotationParserBuilder .toType(Dependency.class) .fromCharSequence(new DependencyStringNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class)) .parser(new DependencyMapNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class)) .fromType(FileCollection.class, new DependencyFilesNotationParser(instantiator)) .fromType(Project.class, new DependencyProjectNotationParser(dependencyFactory)) .fromType(DependencyFactory.ClassPathNotation.class, new DependencyClassPathNotationParser(instantiator, classPathRegistry, fileLookup.getFileResolver())) .invalidNotationMessage("Comprehensive documentation on dependency notations is available in DSL reference for DependencyHandler type.") .toComposite(); }
DependencyFactory createDependencyFactory(Instantiator instantiator, ProjectAccessListener projectAccessListener, StartParameter startParameter, ClassPathRegistry classPathRegistry, FileLookup fileLookup) { DefaultProjectDependencyFactory factory = new DefaultProjectDependencyFactory( projectAccessListener, instantiator, startParameter.isBuildProjectDependencies()); ProjectDependencyFactory projectDependencyFactory = new ProjectDependencyFactory(factory); DependencyProjectNotationParser projParser = new DependencyProjectNotationParser(factory); NotationParser<Object, ? extends Dependency> moduleMapParser = new DependencyMapNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class); NotationParser<Object, ? extends Dependency> moduleStringParser = new DependencyStringNotationParser<DefaultExternalModuleDependency>(instantiator, DefaultExternalModuleDependency.class); NotationParser<Object, ? extends Dependency> selfResolvingDependencyFactory = new DependencyFilesNotationParser(instantiator); List<NotationParser<Object, ? extends Dependency>> notationParsers = Arrays.asList( moduleStringParser, moduleMapParser, selfResolvingDependencyFactory, projParser, new DependencyClassPathNotationParser(instantiator, classPathRegistry, fileLookup.getFileResolver())); return new DefaultDependencyFactory( new DependencyNotationParser(notationParsers), new ClientModuleNotationParserFactory(instantiator).create(), projectDependencyFactory); }
private File compilerLibraryFile(Project project) { return ProjectUtilsKt.getConfiguration("checkerframework.compiler.lib.conf", deps -> { deps.add(new DefaultExternalModuleDependency("org.checkerframework", "compiler", checkerFrameworkExtension(project).getVersion())); return Unit.INSTANCE; }, project.getConfigurations()).getSingleFile(); }
private Set<File> bootClasspathFiles(Project project) { return ProjectUtilsKt.getConfiguration("checkerframework.bootclasspath.lib.conf", deps -> { deps.add(new DefaultExternalModuleDependency("org.checkerframework", "jdk8", checkerFrameworkExtension(project).getVersion())); return Unit.INSTANCE; }, project.getConfigurations()).getFiles(); }
private static Configuration processLibConf(Project project) { return ProjectUtilsKt.getConfiguration("checkerframework.processor.lib.conf", deps -> { deps.add(new DefaultExternalModuleDependency("org.checkerframework", "checker", checkerFrameworkExtension(project).getVersion())); return Unit.INSTANCE; }, project.getConfigurations()); }
@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 proguardCache = new DependencyCache(project, DependencyUtils.createCacheDir(project, PROGUARD_DEPS_CACHE)); proguardCache.build(proguardConfiguration); String proguardJarPath = null; try { Optional<ResolvedArtifactResult> artifactResult = proguardConfiguration.getIncoming().getArtifacts() .getArtifacts() .stream() .filter(artifact -> { ComponentIdentifier identifier = artifact.getId().getComponentIdentifier(); return identifier instanceof ModuleComponentIdentifier && ((ModuleComponentIdentifier) identifier).getGroup().equals(PROGUARD_GROUP) && ((ModuleComponentIdentifier) identifier).getModule().equals(PROGUARD_MODULE); }).findFirst(); if (artifactResult.isPresent()) { proguardJarPath = proguardCache.get( new ExternalDependency( PROGUARD_GROUP, PROGUARD_MODULE, proguardVersion, artifactResult.get().getFile()), true, false); } } catch (IllegalStateException ignored) {} return proguardJarPath; }
public static void addDependency(Project project, String configuration, String groupName, String artifactName, String artifactVersion) { project.getConfigurations() .getByName(configuration) .getDependencies() .add(new DefaultExternalModuleDependency(groupName, artifactName, artifactVersion)); }
private static Dependency lombokDependency(Project project) { return new DefaultExternalModuleDependency("org.projectlombok", "lombok", lombokExtension(project).getVersion()); }
@Override protected void addCompileOnlyDependencies(Project project) { val dep = new DefaultExternalModuleDependency("org.checkerframework", "checker-qual", checkerFrameworkExtension(project).getVersion()); AbstractAnnotationProcessorPlugin.addCompileOnlyDependency(project, dep); }