Search in sources :

Example 1 with PublishException

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

the class Upload method upload.

@TaskAction
protected void upload() {
    getLogger().info("Publishing configuration: {}", configuration);
    DeprecationLogger.deprecateTaskType(Upload.class, getPath()).willBeRemovedInGradle8().withUpgradeGuideSection(7, "upload_task_deprecation").nagUser();
    Module module = ((ConfigurationInternal) configuration).getModule();
    ArtifactPublisher artifactPublisher = getPublicationServices().createArtifactPublisher();
    File descriptorDestination = isUploadDescriptor() ? getDescriptorDestination() : null;
    List<PublicationAwareRepository> publishRepositories = collect(getRepositories(), Transformers.cast(PublicationAwareRepository.class));
    try {
        artifactPublisher.publish(publishRepositories, module, configuration, descriptorDestination);
    } catch (Exception e) {
        throw new PublishException(String.format("Could not publish configuration '%s'", configuration.getName()), e);
    }
}
Also used : ArtifactPublisher(org.gradle.api.internal.artifacts.ArtifactPublisher) PublicationAwareRepository(org.gradle.api.internal.artifacts.repositories.PublicationAwareRepository) PublishException(org.gradle.api.artifacts.PublishException) Module(org.gradle.api.internal.artifacts.Module) File(java.io.File) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal) PublishException(org.gradle.api.artifacts.PublishException)

Example 2 with PublishException

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

the class PublicationErrorChecker method checkForUnpublishableAttributes.

/**
 * Checks that the given component does not have any attributes that are not allowed to be published.
 *
 * @param component the component to check
 * @param documentationRegistry for creating helpful links in error messages upon failing the check
 * @throws PublishException if the component uses attributes invalid for publication
 */
public static void checkForUnpublishableAttributes(SoftwareComponentInternal component, DocumentationRegistry documentationRegistry) {
    for (final UsageContext usageContext : component.getUsages()) {
        Optional<Attribute<?>> category = usageContext.getAttributes().keySet().stream().filter(a -> Category.CATEGORY_ATTRIBUTE.getName().equals(a.getName())).findFirst();
        category.ifPresent(c -> {
            Object value = usageContext.getAttributes().getAttribute(c);
            if (value != null && Category.VERIFICATION.equals(value.toString())) {
                throw new PublishException("Cannot publish module metadata for component '" + component.getName() + "' which would include a variant '" + usageContext.getName() + "' that contains a '" + Category.CATEGORY_ATTRIBUTE.getName() + "' attribute with a value of '" + Category.VERIFICATION + "'.  This attribute is reserved for test verification output and is not publishable.  See: " + documentationRegistry.getDocumentationFor("variant_attributes.html", "sec:verification_category"));
            }
        });
    }
}
Also used : SoftwareComponentInternal(org.gradle.api.internal.component.SoftwareComponentInternal) Attribute(org.gradle.api.attributes.Attribute) Category(org.gradle.api.attributes.Category) Optional(java.util.Optional) DocumentationRegistry(org.gradle.api.internal.DocumentationRegistry) UsageContext(org.gradle.api.internal.component.UsageContext) PublishException(org.gradle.api.artifacts.PublishException) UsageContext(org.gradle.api.internal.component.UsageContext) Attribute(org.gradle.api.attributes.Attribute) PublishException(org.gradle.api.artifacts.PublishException)

Example 3 with PublishException

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

the class DefaultArtifactPublisher method isValidToPublish.

private boolean isValidToPublish(PublishArtifact artifact) {
    File artifactFile = artifact.getFile();
    if (artifactFile.isDirectory()) {
        throw new IllegalArgumentException("Cannot publish a directory (" + artifactFile + ")");
    }
    if (artifactFile.exists()) {
        return true;
    }
    IvyArtifactName ivyArtifactName = DefaultIvyArtifactName.forPublishArtifact(artifact);
    if (!isSigningArtifact(ivyArtifactName)) {
        throw new PublishException(String.format("Cannot publish artifact '%s' (%s) as it does not exist.", ivyArtifactName, artifactFile));
    }
    return false;
}
Also used : DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) PublishException(org.gradle.api.artifacts.PublishException) File(java.io.File)

Aggregations

PublishException (org.gradle.api.artifacts.PublishException)3 File (java.io.File)2 Optional (java.util.Optional)1 Attribute (org.gradle.api.attributes.Attribute)1 Category (org.gradle.api.attributes.Category)1 DocumentationRegistry (org.gradle.api.internal.DocumentationRegistry)1 ArtifactPublisher (org.gradle.api.internal.artifacts.ArtifactPublisher)1 Module (org.gradle.api.internal.artifacts.Module)1 ConfigurationInternal (org.gradle.api.internal.artifacts.configurations.ConfigurationInternal)1 PublicationAwareRepository (org.gradle.api.internal.artifacts.repositories.PublicationAwareRepository)1 SoftwareComponentInternal (org.gradle.api.internal.component.SoftwareComponentInternal)1 UsageContext (org.gradle.api.internal.component.UsageContext)1 DefaultIvyArtifactName (org.gradle.internal.component.model.DefaultIvyArtifactName)1 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)1