Search in sources :

Example 6 with MavenDependency

use of org.gradle.api.publish.maven.MavenDependency 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 7 with MavenDependency

use of org.gradle.api.publish.maven.MavenDependency in project gradle by gradle.

the class GenerateMavenPom method computeMavenPomSpec.

private MavenPomFileGenerator.MavenPomSpec computeMavenPomSpec() {
    MavenPomInternal pomInternal = (MavenPomInternal) getPom();
    MavenPomFileGenerator pomGenerator = new MavenPomFileGenerator(pomInternal.getProjectIdentity(), getVersionRangeMapper(), pomInternal.getVersionMappingStrategy(), compileScopeAttributes.get(), runtimeScopeAttributes.get(), pomInternal.writeGradleMetadataMarker());
    pomGenerator.configureFrom(pomInternal);
    for (MavenDependency mavenDependency : pomInternal.getApiDependencyManagement()) {
        pomGenerator.addApiDependencyManagement(mavenDependency);
    }
    for (MavenDependency mavenDependency : pomInternal.getRuntimeDependencyManagement()) {
        pomGenerator.addRuntimeDependencyManagement(mavenDependency);
    }
    for (MavenDependency mavenDependency : pomInternal.getImportDependencyManagement()) {
        pomGenerator.addImportDependencyManagement(mavenDependency);
    }
    for (MavenDependencyInternal runtimeDependency : pomInternal.getApiDependencies()) {
        pomGenerator.addApiDependency(runtimeDependency);
    }
    for (MavenDependencyInternal runtimeDependency : pomInternal.getRuntimeDependencies()) {
        pomGenerator.addRuntimeDependency(runtimeDependency);
    }
    for (MavenDependencyInternal optionalDependency : pomInternal.getOptionalDependencies()) {
        pomGenerator.addOptionalDependency(optionalDependency);
    }
    pomGenerator.withXml(pomInternal.getXmlAction());
    return pomGenerator.toSpec();
}
Also used : MavenPomInternal(org.gradle.api.publish.maven.internal.publication.MavenPomInternal) MavenPomFileGenerator(org.gradle.api.publish.maven.internal.tasks.MavenPomFileGenerator) MavenDependencyInternal(org.gradle.api.publish.maven.internal.dependencies.MavenDependencyInternal) MavenDependency(org.gradle.api.publish.maven.MavenDependency)

Example 8 with MavenDependency

use of org.gradle.api.publish.maven.MavenDependency in project gradle by gradle.

the class MavenPomFileGenerator method addDependencyManagement.

private void addDependencyManagement(MavenDependencyInternal dependency, String scope) {
    Dependency mavenDependency = new Dependency();
    String groupId = dependency.getGroupId();
    String artifactId = dependency.getArtifactId();
    String projectPath = dependency.getProjectPath();
    ImmutableAttributes attributes = attributesForScope(scope);
    ModuleVersionIdentifier resolvedVersion = versionMappingStrategy.findStrategyForVariant(attributes).maybeResolveVersion(groupId, artifactId, projectPath);
    mavenDependency.setGroupId(resolvedVersion != null ? resolvedVersion.getGroup() : groupId);
    mavenDependency.setArtifactId(resolvedVersion != null ? resolvedVersion.getName() : artifactId);
    mavenDependency.setVersion(resolvedVersion == null ? mapToMavenSyntax(dependency.getVersion()) : resolvedVersion.getVersion());
    String type = dependency.getType();
    if (type != null) {
        mavenDependency.setType(type);
    }
    // Only publish the import scope, others have too different meanings than what Gradle expresses
    if ("import".equals(scope)) {
        mavenDependency.setScope(scope);
    }
    DependencyManagement dependencyManagement = model.getDependencyManagement();
    if (dependencyManagement == null) {
        dependencyManagement = new DependencyManagement();
        model.setDependencyManagement(dependencyManagement);
    }
    dependencyManagement.addDependency(mavenDependency);
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) MavenDependency(org.gradle.api.publish.maven.MavenDependency) Dependency(org.apache.maven.model.Dependency) DependencyManagement(org.apache.maven.model.DependencyManagement)

Aggregations

MavenDependency (org.gradle.api.publish.maven.MavenDependency)8 Dependency (org.apache.maven.model.Dependency)4 MavenDependencyInternal (org.gradle.api.publish.maven.internal.dependencies.MavenDependencyInternal)4 ExcludeRule (org.gradle.api.artifacts.ExcludeRule)3 DependencyManagement (org.apache.maven.model.DependencyManagement)2 Exclusion (org.apache.maven.model.Exclusion)2 DependencyConstraint (org.gradle.api.artifacts.DependencyConstraint)2 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)2 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)2 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)2 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 UsageContext (org.gradle.api.internal.component.UsageContext)2 DefaultMavenDependency (org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency)2 MavenPomInternal (org.gradle.api.publish.maven.internal.publication.MavenPomInternal)2 MavenPomFileGenerator (org.gradle.api.publish.maven.internal.tasks.MavenPomFileGenerator)2 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Capability (org.gradle.api.capabilities.Capability)1 DefaultExcludeRule (org.gradle.api.internal.artifacts.DefaultExcludeRule)1 DefaultProjectDependencyConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependencyConstraint)1