Search in sources :

Example 11 with ProjectDependency

use of org.gradle.api.artifacts.ProjectDependency in project gradle-eta by typelead.

the class EtaInjectDependencies method dependsOnProjects.

public void dependsOnProjects() {
    dependsOn(new Callable<List<Buildable>>() {

        @Override
        public List<Buildable> call() {
            return getProject().getConfigurations().getByName(getTargetConfiguration()).getAllDependencies().stream().filter(dependency -> dependency instanceof ProjectDependency).flatMap(dependency -> {
                final ProjectDependency projectDependency = (ProjectDependency) dependency;
                final Project project = projectDependency.getDependencyProject();
                final String configurationName = projectDependency.getTargetConfiguration();
                return ConfigurationUtils.getConfiguration(project, configurationName).getAllArtifacts().stream();
            }).collect(Collectors.toList());
        }
    });
}
Also used : Buildable(org.gradle.api.Buildable) Project(org.gradle.api.Project) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) Callable(java.util.concurrent.Callable) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Configuration(org.gradle.api.artifacts.Configuration) TaskAction(org.gradle.api.tasks.TaskAction) List(java.util.List) Provider(org.gradle.api.provider.Provider) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) ConfigurationUtils(com.typelead.gradle.eta.internal.ConfigurationUtils) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) DefaultTask(org.gradle.api.DefaultTask) EtaBasePlugin(com.typelead.gradle.eta.plugins.EtaBasePlugin) Input(org.gradle.api.tasks.Input) DefaultEtaConfiguration(com.typelead.gradle.eta.internal.DefaultEtaConfiguration) Dependency(org.gradle.api.artifacts.Dependency) Project(org.gradle.api.Project) ArrayList(java.util.ArrayList) List(java.util.List) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Example 12 with ProjectDependency

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

the class ModuleMetadataFileGenerator method writeDependency.

private void writeDependency(Dependency dependency, JsonWriter jsonWriter) throws IOException {
    jsonWriter.beginObject();
    if (dependency instanceof ProjectDependency) {
        ProjectDependency projectDependency = (ProjectDependency) dependency;
        ModuleVersionIdentifier identifier = projectDependencyResolver.resolve(ModuleVersionIdentifier.class, projectDependency);
        jsonWriter.name("group");
        jsonWriter.value(identifier.getGroup());
        jsonWriter.name("module");
        jsonWriter.value(identifier.getName());
        writeVersionConstraint(DefaultImmutableVersionConstraint.of(identifier.getVersion()), jsonWriter);
    } else {
        jsonWriter.name("group");
        jsonWriter.value(dependency.getGroup());
        jsonWriter.name("module");
        jsonWriter.value(dependency.getName());
        VersionConstraint vc;
        if (dependency instanceof ModuleVersionSelector) {
            vc = ((ExternalDependency) dependency).getVersionConstraint();
        } else {
            vc = DefaultImmutableVersionConstraint.of(Strings.nullToEmpty(dependency.getVersion()));
        }
        writeVersionConstraint(vc, jsonWriter);
    }
    if (dependency instanceof ModuleDependency) {
        writeExcludes((ModuleDependency) dependency, jsonWriter);
    }
    String reason = dependency.getReason();
    if (StringUtils.isNotEmpty(reason)) {
        jsonWriter.name("reason");
        jsonWriter.value(reason);
    }
    jsonWriter.endObject();
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Example 13 with ProjectDependency

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

the class DefaultMavenPublication method from.

public void from(SoftwareComponent component) {
    if (this.component != null) {
        throw new InvalidUserDataException(String.format("Maven publication '%s' cannot include multiple components", name));
    }
    this.component = (SoftwareComponentInternal) component;
    Set<ArtifactKey> seenArtifacts = Sets.newHashSet();
    Set<ModuleDependency> seenDependencies = Sets.newHashSet();
    Set<DependencyConstraint> seenConstraints = Sets.newHashSet();
    for (UsageContext usageContext : getSortedUsageContexts()) {
        // TODO Need a smarter way to map usage to artifact classifier
        for (PublishArtifact publishArtifact : usageContext.getArtifacts()) {
            ArtifactKey key = new ArtifactKey(publishArtifact.getFile(), publishArtifact.getClassifier(), publishArtifact.getExtension());
            if (seenArtifacts.add(key)) {
                artifact(publishArtifact);
            }
        }
        Set<MavenDependencyInternal> dependencies = dependenciesFor(usageContext.getUsage());
        for (ModuleDependency dependency : usageContext.getDependencies()) {
            if (seenDependencies.add(dependency)) {
                if (dependency instanceof ProjectDependency) {
                    addProjectDependency((ProjectDependency) dependency, dependencies);
                } else {
                    addModuleDependency(dependency, dependencies);
                }
            }
        }
        Set<MavenDependency> dependencyConstraints = dependencyConstraintsFor(usageContext.getUsage());
        for (DependencyConstraint dependency : usageContext.getDependencyConstraints()) {
            if (seenConstraints.add(dependency) && !dependency.getVersionConstraint().getPreferredVersion().isEmpty()) {
                addDependencyConstraint(dependency, dependencyConstraints);
            }
        }
    }
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) DependencyConstraint(org.gradle.api.artifacts.DependencyConstraint) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) MavenDependencyInternal(org.gradle.api.publish.maven.internal.dependencies.MavenDependencyInternal) UsageContext(org.gradle.api.internal.component.UsageContext) InvalidUserDataException(org.gradle.api.InvalidUserDataException) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultMavenDependency(org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency) MavenDependency(org.gradle.api.publish.maven.MavenDependency)

Example 14 with ProjectDependency

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

the class DefaultMavenPublication method addDependencyConstraint.

private void addDependencyConstraint(DefaultProjectDependencyConstraint dependency, Set<MavenDependency> dependencies) {
    ProjectDependency projectDependency = dependency.getProjectDependency();
    ModuleVersionIdentifier identifier = projectDependencyResolver.resolve(ModuleVersionIdentifier.class, projectDependency);
    DefaultMavenDependency moduleDependency = new DefaultMavenDependency(identifier.getGroup(), identifier.getName(), identifier.getVersion());
    dependencies.add(new DefaultMavenProjectDependency(moduleDependency, projectDependency.getDependencyProject().getPath()));
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) DefaultMavenDependency(org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency) DefaultMavenProjectDependency(org.gradle.api.publish.maven.internal.dependencies.DefaultMavenProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) DefaultMavenProjectDependency(org.gradle.api.publish.maven.internal.dependencies.DefaultMavenProjectDependency)

Example 15 with ProjectDependency

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

the class DefaultMavenPublication method populateFromComponent.

private void populateFromComponent() {
    if (populated) {
        return;
    }
    populated = true;
    if (component == null) {
        return;
    }
    MavenPublicationErrorChecker.checkForUnpublishableAttributes(component, documentationRegistry);
    PublicationWarningsCollector publicationWarningsCollector = new PublicationWarningsCollector(LOG, UNSUPPORTED_FEATURE, INCOMPATIBLE_FEATURE, PUBLICATION_WARNING_FOOTER, "suppressPomMetadataWarningsFor");
    Set<ArtifactKey> seenArtifacts = Sets.newHashSet();
    Set<PublishedDependency> seenDependencies = Sets.newHashSet();
    Set<DependencyConstraint> seenConstraints = Sets.newHashSet();
    for (UsageContext usageContext : getSortedUsageContexts()) {
        // TODO Need a smarter way to map usage to artifact classifier
        for (PublishArtifact publishArtifact : usageContext.getArtifacts()) {
            ArtifactKey key = new ArtifactKey(publishArtifact.getFile(), publishArtifact.getClassifier(), publishArtifact.getExtension());
            if (!artifactsOverridden && seenArtifacts.add(key)) {
                artifact(publishArtifact);
            }
        }
        Set<ExcludeRule> globalExcludes = usageContext.getGlobalExcludes();
        publicationWarningsCollector.newContext(usageContext.getName());
        Set<MavenDependencyInternal> dependencies = dependenciesFor(usageContext);
        for (ModuleDependency dependency : usageContext.getDependencies()) {
            if (seenDependencies.add(PublishedDependency.of(dependency))) {
                if (isDependencyWithDefaultArtifact(dependency) && dependencyMatchesProject(dependency)) {
                    // We skip all self referencing dependency declarations, unless they have custom artifact information
                    continue;
                }
                if (platformSupport.isTargetingPlatform(dependency)) {
                    if (dependency instanceof ProjectDependency) {
                        addImportDependencyConstraint((ProjectDependency) dependency);
                    } else {
                        if (!versionMappingInUse && isVersionMavenIncompatible(dependency.getVersion())) {
                            publicationWarningsCollector.addIncompatible(String.format("%s:%s:%s declared with a Maven incompatible version notation", dependency.getGroup(), dependency.getName(), dependency.getVersion()));
                        }
                        addImportDependencyConstraint(dependency);
                    }
                } else {
                    if (!dependency.getAttributes().isEmpty()) {
                        publicationWarningsCollector.addUnsupported(String.format("%s:%s:%s declared with Gradle attributes", dependency.getGroup(), dependency.getName(), dependency.getVersion()));
                    }
                    if (dependency instanceof ProjectDependency) {
                        addProjectDependency((ProjectDependency) dependency, globalExcludes, dependencies);
                    } else {
                        if (!versionMappingInUse && isVersionMavenIncompatible(dependency.getVersion())) {
                            publicationWarningsCollector.addIncompatible(String.format("%s:%s:%s declared with a Maven incompatible version notation", dependency.getGroup(), dependency.getName(), dependency.getVersion()));
                        }
                        addModuleDependency(dependency, globalExcludes, dependencies);
                    }
                }
            }
        }
        Set<MavenDependency> dependencyConstraints = dependencyConstraintsFor(usageContext);
        for (DependencyConstraint dependency : usageContext.getDependencyConstraints()) {
            if (seenConstraints.add(dependency)) {
                if (dependency instanceof DefaultProjectDependencyConstraint) {
                    addDependencyConstraint((DefaultProjectDependencyConstraint) dependency, dependencyConstraints);
                } else if (dependency.getVersion() != null) {
                    if (!versionMappingInUse && isVersionMavenIncompatible(dependency.getVersion())) {
                        publicationWarningsCollector.addIncompatible(String.format("constraint %s:%s:%s declared with a Maven incompatible version notation", dependency.getGroup(), dependency.getName(), dependency.getVersion()));
                    }
                    addDependencyConstraint(dependency, dependencyConstraints);
                }
            }
        }
        if (!usageContext.getCapabilities().isEmpty()) {
            for (Capability capability : usageContext.getCapabilities()) {
                if (isNotDefaultCapability(capability)) {
                    publicationWarningsCollector.addVariantUnsupported(String.format("Declares capability %s:%s:%s which cannot be mapped to Maven", capability.getGroup(), capability.getName(), capability.getVersion()));
                }
            }
        }
    }
    if (!silenceAllPublicationWarnings) {
        publicationWarningsCollector.complete(getDisplayName() + " pom metadata", silencedVariants);
    }
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) Capability(org.gradle.api.capabilities.Capability) DependencyConstraint(org.gradle.api.artifacts.DependencyConstraint) DefaultProjectDependencyConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependencyConstraint) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) DefaultMavenProjectDependency(org.gradle.api.publish.maven.internal.dependencies.DefaultMavenProjectDependency) DefaultExcludeRule(org.gradle.api.internal.artifacts.DefaultExcludeRule) ExcludeRule(org.gradle.api.artifacts.ExcludeRule) MavenDependencyInternal(org.gradle.api.publish.maven.internal.dependencies.MavenDependencyInternal) PublicationWarningsCollector(org.gradle.api.publish.internal.validation.PublicationWarningsCollector) UsageContext(org.gradle.api.internal.component.UsageContext) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultProjectDependencyConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependencyConstraint) DefaultMavenDependency(org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency) MavenDependency(org.gradle.api.publish.maven.MavenDependency)

Aggregations

ProjectDependency (org.gradle.api.artifacts.ProjectDependency)18 Dependency (org.gradle.api.artifacts.Dependency)7 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)6 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)4 Configuration (org.gradle.api.artifacts.Configuration)4 DependencyConstraint (org.gradle.api.artifacts.DependencyConstraint)4 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)4 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)3 DefaultEtaConfiguration (com.typelead.gradle.eta.internal.DefaultEtaConfiguration)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)3 Project (org.gradle.api.Project)3 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)3 UsageContext (org.gradle.api.internal.component.UsageContext)3 DefaultMavenDependency (org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency)3 File (java.io.File)2 Collectors (java.util.stream.Collectors)2 Action (org.gradle.api.Action)2 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)2