Search in sources :

Example 21 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency 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)

Example 22 with ModuleDependency

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

the class ArtifactRepositoriesPluginResolver method resolve.

@Override
public void resolve(PluginRequestInternal pluginRequest, PluginResolutionResult result) throws InvalidPluginRequestException {
    ModuleDependency markerDependency = getMarkerDependency(pluginRequest);
    String markerVersion = markerDependency.getVersion();
    if (isNullOrEmpty(markerVersion)) {
        result.notFound(SOURCE_NAME, "plugin dependency must include a version number for this source");
        return;
    }
    if (exists(markerDependency)) {
        handleFound(result, pluginRequest, markerDependency);
    } else {
        handleNotFound(result, "could not resolve plugin artifact '" + getNotation(markerDependency) + "'");
    }
}
Also used : DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency)

Example 23 with ModuleDependency

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

the class ModuleMetadataSpecBuilder method dependenciesOf.

private List<ModuleMetadataSpec.Dependency> dependenciesOf(UsageContext variant) {
    if (variant.getDependencies().isEmpty()) {
        return emptyList();
    }
    ArrayList<ModuleMetadataSpec.Dependency> dependencies = new ArrayList<>();
    Set<ExcludeRule> additionalExcludes = variant.getGlobalExcludes();
    VariantVersionMappingStrategyInternal versionMappingStrategy = versionMappingStrategyFor(variant);
    for (ModuleDependency moduleDependency : variant.getDependencies()) {
        if (moduleDependency.getArtifacts().isEmpty()) {
            dependencies.add(dependencyFor(moduleDependency, additionalExcludes, versionMappingStrategy, null, variant.getName()));
        } else {
            for (DependencyArtifact dependencyArtifact : moduleDependency.getArtifacts()) {
                dependencies.add(dependencyFor(moduleDependency, additionalExcludes, versionMappingStrategy, dependencyArtifact, variant.getName()));
            }
        }
    }
    return dependencies;
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) VariantVersionMappingStrategyInternal(org.gradle.api.publish.internal.versionmapping.VariantVersionMappingStrategyInternal) DependencyArtifact(org.gradle.api.artifacts.DependencyArtifact) ArrayList(java.util.ArrayList) ExternalDependency(org.gradle.api.artifacts.ExternalDependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) DefaultExcludeRule(org.gradle.api.internal.artifacts.DefaultExcludeRule) ExcludeRule(org.gradle.api.artifacts.ExcludeRule)

Example 24 with ModuleDependency

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

the class DefaultClientModule method copy.

@Override
public ClientModule copy() {
    DefaultClientModule copiedClientModule = new DefaultClientModule(getGroup(), getName(), getVersion(), getTargetConfiguration());
    copyTo(copiedClientModule);
    for (ModuleDependency dependency : dependencies) {
        copiedClientModule.addDependency(dependency.copy());
    }
    return copiedClientModule;
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency)

Example 25 with ModuleDependency

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

the class ClientModuleResolver method createClientModuleDependencies.

private List<ModuleDependencyMetadata> createClientModuleDependencies(ComponentIdentifier identifier, ClientModule clientModule) {
    List<ModuleDependencyMetadata> dependencies = Lists.newArrayList();
    for (ModuleDependency moduleDependency : clientModule.getDependencies()) {
        ModuleDependencyMetadata dependencyMetadata = createDependencyMetadata(identifier, moduleDependency);
        dependencies.add(dependencyMetadata);
    }
    return dependencies;
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) ModuleDependencyMetadata(org.gradle.internal.component.external.model.ModuleDependencyMetadata)

Aggregations

ModuleDependency (org.gradle.api.artifacts.ModuleDependency)25 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)8 Dependency (org.gradle.api.artifacts.Dependency)6 Test (org.junit.Test)5 Closure (groovy.lang.Closure)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)3 DependencyConstraint (org.gradle.api.artifacts.DependencyConstraint)3 ExternalModuleDependency (org.gradle.api.artifacts.ExternalModuleDependency)3 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)3 UsageContext (org.gradle.api.internal.component.UsageContext)3 HashMap (java.util.HashMap)2 ExcludeRule (org.gradle.api.artifacts.ExcludeRule)2 ExternalDependency (org.gradle.api.artifacts.ExternalDependency)2 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)2 MinimalExternalModuleDependency (org.gradle.api.artifacts.MinimalExternalModuleDependency)2 HasConfigurableAttributes (org.gradle.api.attributes.HasConfigurableAttributes)2 Capability (org.gradle.api.capabilities.Capability)2 DefaultExcludeRule (org.gradle.api.internal.artifacts.DefaultExcludeRule)2 MavenDependency (org.gradle.api.publish.maven.MavenDependency)2 DefaultMavenDependency (org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency)2