Search in sources :

Example 1 with MavenPublication

use of org.gradle.api.publish.maven.MavenPublication in project build-info by JFrogDev.

the class TaskHelperPublications method getArtifactDeployDetails.

public Set<GradleDeployDetails> getArtifactDeployDetails() {
    Set<GradleDeployDetails> deployDetails = Sets.newLinkedHashSet();
    if (!hasPublications()) {
        log.info("No publications to publish for project '{}'.", getProject().getPath());
        return deployDetails;
    }
    for (IvyPublication ivyPublication : ivyPublications) {
        String publicationName = ivyPublication.getName();
        if (!(ivyPublication instanceof IvyPublicationInternal)) {
            // TODO: Check how the descriptor file can be extracted without using asNormalisedPublication
            log.warn("Ivy publication name '{}' is of unsupported type '{}'!", publicationName, ivyPublication.getClass());
            continue;
        }
        IvyPublicationInternal ivyPublicationInternal = (IvyPublicationInternal) ivyPublication;
        IvyNormalizedPublication ivyNormalizedPublication = ivyPublicationInternal.asNormalisedPublication();
        IvyPublicationIdentity projectIdentity = ivyNormalizedPublication.getProjectIdentity();
        Map<QName, String> extraInfo = ivyPublication.getDescriptor().getExtraInfo().asMap();
        // First adding the Ivy descriptor (if the build is configured to add it):
        if (isPublishIvy()) {
            File file = getIvyDescriptorFile(ivyNormalizedPublication);
            DeployDetails.Builder builder = createBuilder(file, publicationName);
            if (builder != null) {
                PublishArtifactInfo artifactInfo = new PublishArtifactInfo(projectIdentity.getModule(), "xml", "ivy", null, extraInfo, file);
                addIvyArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
            }
        }
        IvyArtifactSet artifacts = ivyPublication.getArtifacts();
        for (IvyArtifact artifact : artifacts) {
            File file = artifact.getFile();
            DeployDetails.Builder builder = createBuilder(file, publicationName);
            if (builder == null)
                continue;
            PublishArtifactInfo artifactInfo = new PublishArtifactInfo(artifact.getName(), artifact.getExtension(), artifact.getType(), artifact.getClassifier(), extraInfo, file);
            addIvyArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
        }
    }
    for (MavenPublication mavenPublication : mavenPublications) {
        String publicationName = mavenPublication.getName();
        if (!(mavenPublication instanceof MavenPublicationInternal)) {
            // TODO: Check how the descriptor file can be extracted without using asNormalisedPublication
            log.warn("Maven publication name '{}' is of unsupported type '{}'!", publicationName, mavenPublication.getClass());
            continue;
        }
        MavenPublicationInternal mavenPublicationInternal = (MavenPublicationInternal) mavenPublication;
        MavenNormalizedPublication mavenNormalizedPublication = mavenPublicationInternal.asNormalisedPublication();
        MavenProjectIdentity projectIdentity = mavenNormalizedPublication.getProjectIdentity();
        // First adding the Maven descriptor (if the build is configured to add it):
        if (isPublishMaven()) {
            File file = mavenNormalizedPublication.getPomFile();
            DeployDetails.Builder builder = createBuilder(file, publicationName);
            if (builder != null) {
                PublishArtifactInfo artifactInfo = new PublishArtifactInfo(projectIdentity.getArtifactId(), "pom", "pom", null, file);
                addMavenArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
            }
        }
        MavenArtifactSet artifacts = mavenPublication.getArtifacts();
        for (MavenArtifact artifact : artifacts) {
            File file = artifact.getFile();
            DeployDetails.Builder builder = createBuilder(file, publicationName);
            if (builder == null)
                continue;
            PublishArtifactInfo artifactInfo = new PublishArtifactInfo(projectIdentity.getArtifactId(), artifact.getExtension(), artifact.getExtension(), artifact.getClassifier(), file);
            addMavenArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
        }
    }
    return deployDetails;
}
Also used : DeployDetails(org.jfrog.build.client.DeployDetails) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) PublishArtifactInfo(org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo) QName(javax.xml.namespace.QName) MavenPublication(org.gradle.api.publish.maven.MavenPublication) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) MavenProjectIdentity(org.gradle.api.publish.maven.internal.publisher.MavenProjectIdentity) IvyPublicationIdentity(org.gradle.api.publish.ivy.internal.publisher.IvyPublicationIdentity) MavenNormalizedPublication(org.gradle.api.publish.maven.internal.publisher.MavenNormalizedPublication) IvyArtifactSet(org.gradle.api.publish.ivy.IvyArtifactSet) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) IvyNormalizedPublication(org.gradle.api.publish.ivy.internal.publisher.IvyNormalizedPublication) IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) MavenArtifactSet(org.gradle.api.publish.maven.MavenArtifactSet) IvyArtifact(org.gradle.api.publish.ivy.IvyArtifact) File(java.io.File) MavenArtifact(org.gradle.api.publish.maven.MavenArtifact) IvyPublication(org.gradle.api.publish.ivy.IvyPublication)

Example 2 with MavenPublication

use of org.gradle.api.publish.maven.MavenPublication in project build-info by JFrogDev.

the class TaskHelperPublications method checkDependsOnArtifactsToPublish.

public void checkDependsOnArtifactsToPublish() {
    // If no publications in the list
    if (!hasPublications()) {
        // If some were declared => Warning
        if (publishPublicationsSpecified) {
            log.warn("None of the specified publications matched for project '{}' - nothing to publish.", getProject().getPath());
        } else {
            log.debug("No publications specified for project '{}'", getProject().getPath());
        }
        return;
    }
    for (IvyPublication ivyPublication : ivyPublications) {
        if (!(ivyPublication instanceof IvyPublicationInternal)) {
            // TODO: Check how the output files can be extracted without using getPublishableFiles
            log.warn("Ivy publication name '{}' is of unsupported type '{}'!", ivyPublication.getName(), ivyPublication.getClass());
            continue;
        }
        dependsOn(((IvyPublicationInternal) ivyPublication).getPublishableFiles());
        String capitalizedPublicationName = ivyPublication.getName().substring(0, 1).toUpperCase() + ivyPublication.getName().substring(1);
        dependsOn(String.format("%s:generateDescriptorFileFor%sPublication", getProject().getPath(), capitalizedPublicationName));
    }
    for (MavenPublication mavenPublication : mavenPublications) {
        if (!(mavenPublication instanceof MavenPublicationInternal)) {
            // TODO: Check how the output files can be extracted without using getPublishableFiles
            log.warn("Maven publication name '{}' is of unsupported type '{}'!", mavenPublication.getName(), mavenPublication.getClass());
            continue;
        }
        dependsOn(((MavenPublicationInternal) mavenPublication).getPublishableFiles());
        String capitalizedPublicationName = mavenPublication.getName().substring(0, 1).toUpperCase() + mavenPublication.getName().substring(1);
        dependsOn(String.format("%s:generatePomFileFor%sPublication", getProject().getPath(), capitalizedPublicationName));
    }
}
Also used : IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) MavenPublication(org.gradle.api.publish.maven.MavenPublication) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) IvyPublication(org.gradle.api.publish.ivy.IvyPublication)

Example 3 with MavenPublication

use of org.gradle.api.publish.maven.MavenPublication in project spring-security by spring-projects.

the class PublishAllJavaComponentsPlugin method apply.

@Override
public void apply(Project project) {
    project.getPlugins().withType(MavenPublishPlugin.class).all((mavenPublish) -> {
        PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
        publishing.getPublications().create("mavenJava", MavenPublication.class, new Action<MavenPublication>() {

            @Override
            public void execute(MavenPublication maven) {
                project.getPlugins().withType(JavaPlugin.class, (plugin) -> {
                    maven.from(project.getComponents().getByName("java"));
                });
                project.getPlugins().withType(JavaPlatformPlugin.class, (plugin) -> {
                    maven.from(project.getComponents().getByName("javaPlatform"));
                });
            }
        });
    });
}
Also used : PublishingExtension(org.gradle.api.publish.PublishingExtension) Action(org.gradle.api.Action) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin) Project(org.gradle.api.Project) VariantVersionMappingStrategy(org.gradle.api.publish.VariantVersionMappingStrategy) MavenPublishPlugin(org.gradle.api.publish.maven.plugins.MavenPublishPlugin) JavaPlugin(org.gradle.api.plugins.JavaPlugin) MavenPublication(org.gradle.api.publish.maven.MavenPublication) Plugin(org.gradle.api.Plugin) VersionMappingStrategy(org.gradle.api.publish.VersionMappingStrategy) MavenPublishPlugin(org.gradle.api.publish.maven.plugins.MavenPublishPlugin) MavenPublication(org.gradle.api.publish.maven.MavenPublication) JavaPlugin(org.gradle.api.plugins.JavaPlugin) PublishingExtension(org.gradle.api.publish.PublishingExtension) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin)

Example 4 with MavenPublication

use of org.gradle.api.publish.maven.MavenPublication in project coffeenet-starter by coffeenet.

the class DeployedPlugin method apply.

@Override
public void apply(Project project) {
    project.getPlugins().apply(MavenPublishPlugin.class);
    // Create a new Maven publication
    PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
    MavenPublication mavenPublication = publishing.getPublications().create("maven", MavenPublication.class);
    mavenPublication.suppressAllPomMetadataWarnings();
    // Publish all Java artifacts and the platform BOMs
    // J-
    // @formatter:off
    project.getPlugins().withType(JavaPlugin.class).all((plugin) -> project.getComponents().matching((component) -> component.getName().equals("java")).all(mavenPublication::from));
    project.getPlugins().withType(JavaPlatformPlugin.class).all((plugin) -> project.getComponents().matching((component) -> component.getName().equals("javaPlatform")).all(mavenPublication::from));
    if (project.hasProperty(SIGN_GPG_PROPERTY_NAME)) {
        applyGpgSigning(project, mavenPublication);
    }
// @formatter:on
// J+
}
Also used : MavenPublication(org.gradle.api.publish.maven.MavenPublication) JavaPlugin(org.gradle.api.plugins.JavaPlugin) PublishingExtension(org.gradle.api.publish.PublishingExtension) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin)

Example 5 with MavenPublication

use of org.gradle.api.publish.maven.MavenPublication in project spring-boot by spring-projects.

the class MavenPublishingConventions method apply.

void apply(Project project) {
    project.getPlugins().withType(MavenPublishPlugin.class).all((mavenPublish) -> {
        PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
        if (project.hasProperty("deploymentRepository")) {
            publishing.getRepositories().maven((mavenRepository) -> {
                mavenRepository.setUrl(project.property("deploymentRepository"));
                mavenRepository.setName("deployment");
            });
        }
        publishing.getPublications().withType(MavenPublication.class).all((mavenPublication) -> customizeMavenPublication(mavenPublication, project));
        project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> {
            JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
            extension.withJavadocJar();
            extension.withSourcesJar();
        });
    });
}
Also used : MavenPublishPlugin(org.gradle.api.publish.maven.plugins.MavenPublishPlugin) MavenPublication(org.gradle.api.publish.maven.MavenPublication) JavaPlugin(org.gradle.api.plugins.JavaPlugin) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) PublishingExtension(org.gradle.api.publish.PublishingExtension)

Aggregations

MavenPublication (org.gradle.api.publish.maven.MavenPublication)13 JavaPlugin (org.gradle.api.plugins.JavaPlugin)6 PublishingExtension (org.gradle.api.publish.PublishingExtension)6 MavenPublishPlugin (org.gradle.api.publish.maven.plugins.MavenPublishPlugin)5 Plugin (org.gradle.api.Plugin)4 Project (org.gradle.api.Project)4 XmlProvider (org.gradle.api.XmlProvider)3 JavaPlatformPlugin (org.gradle.api.plugins.JavaPlatformPlugin)3 MavenPublicationInternal (org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal)3 PluginContainer (org.gradle.api.plugins.PluginContainer)2 IvyPublication (org.gradle.api.publish.ivy.IvyPublication)2 IvyPublicationInternal (org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal)2 SpotlessExtension (com.diffplug.gradle.spotless.SpotlessExtension)1 SpotlessPlugin (com.diffplug.gradle.spotless.SpotlessPlugin)1 VersionsPlugin (com.github.benmanes.gradle.versions.VersionsPlugin)1 DependencyUpdatesTask (com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1