Search in sources :

Example 26 with PublishArtifact

use of org.gradle.api.artifacts.PublishArtifact 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 27 with PublishArtifact

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

the class JavaPlugin method configureArchivesAndComponent.

private void configureArchivesAndComponent(Project project, final JavaPluginExtension pluginExtension) {
    PublishArtifact jarArtifact = new LazyPublishArtifact(registerJarTaskFor(project, pluginExtension), ((ProjectInternal) project).getFileResolver());
    Configuration apiElementConfiguration = project.getConfigurations().getByName(API_ELEMENTS_CONFIGURATION_NAME);
    Configuration runtimeElementsConfiguration = project.getConfigurations().getByName(RUNTIME_ELEMENTS_CONFIGURATION_NAME);
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(jarArtifact);
    Provider<ProcessResources> processResources = project.getTasks().named(PROCESS_RESOURCES_TASK_NAME, ProcessResources.class);
    addJar(apiElementConfiguration, jarArtifact);
    addRuntimeVariants(runtimeElementsConfiguration, jarArtifact, mainSourceSetOf(pluginExtension), processResources);
    registerSoftwareComponents(project);
}
Also used : LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) DefaultArtifactPublicationSet(org.gradle.api.internal.plugins.DefaultArtifactPublicationSet) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) Configuration(org.gradle.api.artifacts.Configuration) ProcessResources(org.gradle.language.jvm.tasks.ProcessResources) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) PublishArtifact(org.gradle.api.artifacts.PublishArtifact)

Example 28 with PublishArtifact

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

the class PublishArtifactLocalArtifactMetadataSerializer method write.

@Override
public void write(Encoder encoder, PublishArtifactLocalArtifactMetadata value) throws Exception {
    componentIdentifierSerializer.write(encoder, value.getComponentIdentifier());
    PublishArtifact publishArtifact = value.getPublishArtifact();
    encoder.writeString(publishArtifact.getName());
    encoder.writeString(publishArtifact.getType());
    encoder.writeString(publishArtifact.getExtension());
    encoder.writeNullableString(publishArtifact.getClassifier());
    encoder.writeString(publishArtifact.getFile().getCanonicalPath());
}
Also used : ImmutablePublishArtifact(org.gradle.api.internal.artifacts.publish.ImmutablePublishArtifact) PublishArtifact(org.gradle.api.artifacts.PublishArtifact)

Example 29 with PublishArtifact

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

the class DefaultArtifactPublisher method addConfigurations.

private void addConfigurations(DefaultIvyModulePublishMetadata metaData, Collection<? extends ConfigurationInternal> configurations, boolean validateArtifacts) {
    for (ConfigurationInternal configuration : configurations) {
        BuildableLocalConfigurationMetadata configurationMetadata = addConfiguration(metaData, configuration);
        dependenciesConverter.addDependenciesAndExcludes(configurationMetadata, configuration);
        OutgoingVariant outgoingVariant = configuration.convertToOutgoingVariant();
        for (PublishArtifact publishArtifact : outgoingVariant.getArtifacts()) {
            if (!validateArtifacts || isValidToPublish(publishArtifact)) {
                metaData.addArtifact(configuration.getName(), publishArtifact);
            }
        }
    }
}
Also used : OutgoingVariant(org.gradle.api.internal.artifacts.configurations.OutgoingVariant) BuildableLocalConfigurationMetadata(org.gradle.internal.component.local.model.BuildableLocalConfigurationMetadata) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal)

Example 30 with PublishArtifact

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

the class DefaultLocalComponentMetadata method addVariant.

@Override
public void addVariant(String configuration, String name, VariantResolveMetadata.Identifier identifier, DisplayName displayName, ImmutableAttributes attributes, ImmutableCapabilities capabilities, Collection<? extends PublishArtifact> publishArtifacts) {
    ImmutableList<LocalComponentArtifactMetadata> artifacts;
    if (publishArtifacts.isEmpty()) {
        artifacts = ImmutableList.of();
    } else {
        ImmutableList.Builder<LocalComponentArtifactMetadata> builder = ImmutableList.builder();
        for (PublishArtifact artifact : publishArtifacts) {
            builder.add(new PublishArtifactLocalArtifactMetadata(componentId, artifact));
        }
        artifacts = builder.build();
    }
    allVariants.put(configuration, new DefaultVariantMetadata(name, identifier, displayName, attributes, artifacts, capabilities));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultVariantMetadata(org.gradle.internal.component.model.DefaultVariantMetadata)

Aggregations

PublishArtifact (org.gradle.api.artifacts.PublishArtifact)30 File (java.io.File)9 DefaultPublishArtifact (org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact)5 Configuration (org.gradle.api.artifacts.Configuration)4 UsageContext (org.gradle.api.internal.component.UsageContext)4 Artifact (org.apache.ivy.core.module.descriptor.Artifact)3 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)3 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)3 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)3 LazyPublishArtifact (org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact)3 DefaultArtifactPublicationSet (org.gradle.api.internal.plugins.DefaultArtifactPublicationSet)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 EnumMap (java.util.EnumMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Task (org.gradle.api.Task)2 Dependency (org.gradle.api.artifacts.Dependency)2 DependencyConstraint (org.gradle.api.artifacts.DependencyConstraint)2