Search in sources :

Example 46 with Dependency

use of org.gradle.api.artifacts.Dependency in project spring-boot by spring-projects.

the class CheckClasspathForUnnecessaryExclusions method checkForUnnecessaryExclusions.

@TaskAction
public void checkForUnnecessaryExclusions() {
    Map<String, Set<String>> unnecessaryExclusions = new HashMap<>();
    this.exclusionsByDependencyId.forEach((dependencyId, exclusions) -> {
        if (!exclusions.isEmpty()) {
            Dependency toCheck = this.dependencyById.get(dependencyId);
            List<String> dependencies = this.configurations.detachedConfiguration(toCheck, this.platform).getIncoming().getArtifacts().getArtifacts().stream().map(this::getId).collect(Collectors.toList());
            exclusions.removeAll(dependencies);
            removeProfileExclusions(dependencyId, exclusions);
            if (!exclusions.isEmpty()) {
                unnecessaryExclusions.put(dependencyId, exclusions);
            }
        }
    });
    if (!unnecessaryExclusions.isEmpty()) {
        throw new GradleException(getExceptionMessage(unnecessaryExclusions));
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) GradleException(org.gradle.api.GradleException) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) Dependency(org.gradle.api.artifacts.Dependency) TaskAction(org.gradle.api.tasks.TaskAction)

Example 47 with Dependency

use of org.gradle.api.artifacts.Dependency in project gradle by gradle.

the class GroovyRuntime method inferGroovyClasspath.

/**
 * Searches the specified class path for Groovy Jars ({@code groovy(-indy)}, {@code groovy-all(-indy)}) and returns a corresponding class path for executing Groovy tools such as the Groovy
 * compiler and Groovydoc tool. The tool versions will match those of the Groovy Jars found. If no Groovy Jars are found on the specified class path, a class path with the contents of the {@code
 * groovy} configuration will be 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 Groovy Jars
 * @return a corresponding class path for executing Groovy tools such as the Groovy compiler and Groovydoc tool
 */
public FileCollection inferGroovyClasspath(final Iterable<File> classpath) {
    // would differ in at least the following ways: 1. live 2. no autowiring
    return new LazilyInitializedFileCollection() {

        @Override
        public String getDisplayName() {
            return "Groovy runtime classpath";
        }

        @Override
        public FileCollection createDelegate() {
            try {
                return inferGroovyClasspath();
            } catch (RuntimeException e) {
                return new FailingFileCollection(getDisplayName(), e);
            }
        }

        private FileCollection inferGroovyClasspath() {
            GroovyJarFile groovyJar = findGroovyJarFile(classpath);
            if (groovyJar == null) {
                throw new GradleException(String.format("Cannot infer Groovy class path because no Groovy Jar was found on class path: %s", Iterables.toString(classpath)));
            }
            if (groovyJar.isGroovyAll()) {
                return project.getLayout().files(groovyJar.getFile());
            }
            VersionNumber groovyVersion = groovyJar.getVersion();
            // Groovy 3 does not have groovy-all yet we may have the required pieces on classpath via localGroovy()
            if (groovyVersion.getMajor() == 3) {
                return inferGroovy3Classpath(groovyVersion);
            }
            String notation = groovyJar.getDependencyNotation();
            List<Dependency> dependencies = new ArrayList<>();
            addDependencyTo(dependencies, notation);
            if (groovyVersion.compareTo(GROOVY_VERSION_WITH_SEPARATE_ANT) >= 0) {
                // add groovy-ant to bring in Groovydoc for Groovy 2.0+
                addGroovyDependency(notation, dependencies, "groovy-ant");
            }
            if (groovyVersion.compareTo(GROOVY_VERSION_REQUIRING_TEMPLATES) >= 0) {
                // add groovy-templates for Groovy 2.5+
                addGroovyDependency(notation, dependencies, "groovy-templates");
            }
            return detachedRuntimeClasspath(dependencies.toArray(new Dependency[0]));
        }

        private void addGroovyDependency(String groovyDependencyNotion, List<Dependency> dependencies, String otherDependency) {
            String notation = groovyDependencyNotion.replace(":groovy:", ":" + otherDependency + ":");
            addDependencyTo(dependencies, notation);
        }

        private void addDependencyTo(List<Dependency> dependencies, String notation) {
            // project.getDependencies().create(String) seems to be the only feasible way to create a Dependency with a classifier
            dependencies.add(project.getDependencies().create(notation));
        }

        private FileCollection inferGroovy3Classpath(VersionNumber groovyVersion) {
            Set<String> groovyJarNames = groovyJarNamesFor(groovyVersion);
            List<File> groovyClasspath = collectJarsFromClasspath(classpath, groovyJarNames);
            if (groovyClasspath.size() == GROOVY3_LIBS.size()) {
                return project.getLayout().files(groovyClasspath);
            }
            return detachedRuntimeClasspath(GROOVY3_LIBS.stream().map(libName -> project.getDependencies().create("org.codehaus.groovy:" + libName + ":" + groovyVersion)).toArray(Dependency[]::new));
        }

        private Configuration detachedRuntimeClasspath(Dependency... dependencies) {
            Configuration classpath = project.getConfigurations().detachedConfiguration(dependencies);
            jvmEcosystemUtilities().configureAsRuntimeClasspath(classpath);
            return classpath;
        }

        // 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);
            }
        }
    };
}
Also used : GroovyJarFile(org.gradle.api.internal.plugins.GroovyJarFile) Configuration(org.gradle.api.artifacts.Configuration) TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext) ArrayList(java.util.ArrayList) LazilyInitializedFileCollection(org.gradle.api.internal.file.collections.LazilyInitializedFileCollection) Dependency(org.gradle.api.artifacts.Dependency) VersionNumber(org.gradle.util.internal.VersionNumber) FailingFileCollection(org.gradle.api.internal.file.collections.FailingFileCollection) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) GroovyJarFile(org.gradle.api.internal.plugins.GroovyJarFile) File(java.io.File) Buildable(org.gradle.api.Buildable)

Example 48 with Dependency

use of org.gradle.api.artifacts.Dependency in project gradle by gradle.

the class DefaultAutoAppliedPluginHandler method isAlreadyRequestedInBuildScriptBlock.

private static boolean isAlreadyRequestedInBuildScriptBlock(PluginRequestInternal autoAppliedPlugin, ScriptHandler scriptHandler) {
    ModuleVersionSelector module = autoAppliedPlugin.getModule();
    if (module == null) {
        return false;
    }
    Configuration classpathConfiguration = scriptHandler.getConfigurations().getByName(ScriptHandler.CLASSPATH_CONFIGURATION);
    for (Dependency dependency : classpathConfiguration.getDependencies()) {
        if (module.getGroup().equals(dependency.getGroup()) && module.getName().equals(dependency.getName())) {
            return true;
        }
    }
    return false;
}
Also used : ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) Configuration(org.gradle.api.artifacts.Configuration) Dependency(org.gradle.api.artifacts.Dependency)

Example 49 with Dependency

use of org.gradle.api.artifacts.Dependency in project gradle by gradle.

the class DefaultDependencyFactory method createDependency.

@Override
public Dependency createDependency(Object dependencyNotation) {
    Dependency dependency = dependencyNotationParser.parseNotation(dependencyNotation);
    injectServices(dependency);
    return dependency;
}
Also used : ProjectDependency(org.gradle.api.artifacts.ProjectDependency) AbstractModuleDependency(org.gradle.api.internal.artifacts.dependencies.AbstractModuleDependency) Dependency(org.gradle.api.artifacts.Dependency)

Example 50 with Dependency

use of org.gradle.api.artifacts.Dependency in project gradle by gradle.

the class DefaultDependencyHandler method platform.

@Override
public Dependency platform(Object notation, Action<? super Dependency> configureAction) {
    Dependency dep = platform(notation);
    configureAction.execute(dep);
    return dep;
}
Also used : ExternalModuleDependency(org.gradle.api.artifacts.ExternalModuleDependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) MinimalExternalModuleDependency(org.gradle.api.artifacts.MinimalExternalModuleDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) Dependency(org.gradle.api.artifacts.Dependency)

Aggregations

Dependency (org.gradle.api.artifacts.Dependency)58 Configuration (org.gradle.api.artifacts.Configuration)20 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)16 File (java.io.File)13 Project (org.gradle.api.Project)13 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)12 ExternalModuleDependency (org.gradle.api.artifacts.ExternalModuleDependency)8 MinimalExternalModuleDependency (org.gradle.api.artifacts.MinimalExternalModuleDependency)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)6 Collectors (java.util.stream.Collectors)5 Inject (javax.inject.Inject)5 DependencySet (org.gradle.api.artifacts.DependencySet)5 ObjectFactory (org.gradle.api.model.ObjectFactory)5 TaskDependency (org.gradle.api.tasks.TaskDependency)5 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)4 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)4 Map (java.util.Map)4 Provider (org.gradle.api.provider.Provider)4