Search in sources :

Example 6 with MavenPublication

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

the class DeployedPlugin method apply.

@Override
@SuppressWarnings("deprecation")
public void apply(Project project) {
    project.getPlugins().apply(MavenPublishPlugin.class);
    project.getPlugins().apply(MavenRepositoryPlugin.class);
    PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
    MavenPublication mavenPublication = publishing.getPublications().create("maven", MavenPublication.class);
    project.afterEvaluate((evaluated) -> {
        project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> {
            if (((Jar) project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME)).isEnabled()) {
                project.getComponents().matching((component) -> component.getName().equals("java")).all((javaComponent) -> mavenPublication.from(javaComponent));
            }
        });
    });
    project.getPlugins().withType(JavaPlatformPlugin.class).all((javaPlugin) -> project.getComponents().matching((component) -> component.getName().equals("javaPlatform")).all((javaComponent) -> mavenPublication.from(javaComponent)));
}
Also used : PublishingExtension(org.gradle.api.publish.PublishingExtension) Jar(org.gradle.api.tasks.bundling.Jar) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin) Project(org.gradle.api.Project) 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) MavenPublication(org.gradle.api.publish.maven.MavenPublication) JavaPlugin(org.gradle.api.plugins.JavaPlugin) Jar(org.gradle.api.tasks.bundling.Jar) PublishingExtension(org.gradle.api.publish.PublishingExtension) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin)

Example 7 with MavenPublication

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

the class MavenPluginPublishPlugin method createMavenMarkerPublication.

private void createMavenMarkerPublication(PluginDeclaration declaration, final MavenPublication coordinates, PublicationContainer publications) {
    String pluginId = declaration.getId();
    String pluginGroupId = coordinates.getGroupId();
    String pluginArtifactId = coordinates.getArtifactId();
    String pluginVersion = coordinates.getVersion();
    MavenPublicationInternal publication = (MavenPublicationInternal) publications.create(declaration.getName() + "PluginMarkerMaven", MavenPublication.class);
    publication.setAlias(true);
    publication.setArtifactId(pluginId + PLUGIN_MARKER_SUFFIX);
    publication.setGroupId(pluginId);
    publication.getPom().withXml(new Action<XmlProvider>() {

        @Override
        public void execute(XmlProvider xmlProvider) {
            Element root = xmlProvider.asElement();
            Document document = root.getOwnerDocument();
            Node dependencies = root.appendChild(document.createElement("dependencies"));
            Node dependency = dependencies.appendChild(document.createElement("dependency"));
            Node groupId = dependency.appendChild(document.createElement("groupId"));
            groupId.setTextContent(pluginGroupId);
            Node artifactId = dependency.appendChild(document.createElement("artifactId"));
            artifactId.setTextContent(pluginArtifactId);
            Node version = dependency.appendChild(document.createElement("version"));
            version.setTextContent(pluginVersion);
        }
    });
    publication.getPom().getName().set(declaration.getDisplayName());
    publication.getPom().getDescription().set(declaration.getDescription());
}
Also used : XmlProvider(org.gradle.api.XmlProvider) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) MavenPublication(org.gradle.api.publish.maven.MavenPublication) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) Document(org.w3c.dom.Document)

Example 8 with MavenPublication

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

the class MavenPluginPublishingRules method createMavenMarkerPublication.

private void createMavenMarkerPublication(PluginDeclaration declaration, final MavenPublication coordinates, PublicationContainer publications) {
    String pluginId = declaration.getId();
    MavenPublicationInternal publication = (MavenPublicationInternal) publications.create(declaration.getName() + "PluginMarkerMaven", MavenPublication.class);
    publication.setAlias(true);
    publication.setArtifactId(pluginId + PLUGIN_MARKER_SUFFIX);
    publication.setGroupId(pluginId);
    publication.getPom().withXml(new Action<XmlProvider>() {

        @Override
        public void execute(XmlProvider xmlProvider) {
            Element root = xmlProvider.asElement();
            Document document = root.getOwnerDocument();
            Node dependencies = root.appendChild(document.createElement("dependencies"));
            Node dependency = dependencies.appendChild(document.createElement("dependency"));
            Node groupId = dependency.appendChild(document.createElement("groupId"));
            groupId.setTextContent(coordinates.getGroupId());
            Node artifactId = dependency.appendChild(document.createElement("artifactId"));
            artifactId.setTextContent(coordinates.getArtifactId());
            Node version = dependency.appendChild(document.createElement("version"));
            version.setTextContent(coordinates.getVersion());
        }
    });
}
Also used : XmlProvider(org.gradle.api.XmlProvider) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) MavenPublication(org.gradle.api.publish.maven.MavenPublication) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) Document(org.w3c.dom.Document)

Example 9 with MavenPublication

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

the class MavenPluginPublishingRules method createMavenPluginPublication.

private void createMavenPluginPublication(SoftwareComponent component, PublicationContainer publications) {
    MavenPublication publication = publications.maybeCreate("pluginMaven", MavenPublication.class);
    publication.from(component);
}
Also used : MavenPublication(org.gradle.api.publish.maven.MavenPublication)

Example 10 with MavenPublication

use of org.gradle.api.publish.maven.MavenPublication in project shipkit by mockito.

the class JavaPublishPlugin method apply.

public void apply(final Project project) {
    final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration();
    project.getPlugins().apply(JavaLibraryPlugin.class);
    project.getPlugins().apply("maven-publish");
    final Jar sourcesJar = (Jar) project.getTasks().getByName(JavaLibraryPlugin.SOURCES_JAR_TASK);
    final Jar javadocJar = (Jar) project.getTasks().getByName(JavaLibraryPlugin.JAVADOC_JAR_TASK);
    GradleDSLHelper.publications(project, new Action<PublicationContainer>() {

        public void execute(PublicationContainer publications) {
            MavenPublication p = publications.create(PUBLICATION_NAME, MavenPublication.class, new Action<MavenPublication>() {

                public void execute(MavenPublication publication) {
                    publication.from(project.getComponents().getByName("java"));
                    publication.artifact(sourcesJar);
                    publication.artifact(javadocJar);
                    publication.setArtifactId(((Jar) project.getTasks().getByName("jar")).getBaseName());
                    PomCustomizer.customizePom(project, conf, publication);
                }
            });
            LOG.info("{} - configured '{}' publication", project.getPath(), p.getArtifactId());
        }
    });
    // so that we flesh out problems with maven publication during the build process
    project.getTasks().getByName("build").dependsOn("publishToMavenLocal");
}
Also used : Action(org.gradle.api.Action) ShipkitConfiguration(org.shipkit.gradle.configuration.ShipkitConfiguration) ShipkitConfigurationPlugin(org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin) PublicationContainer(org.gradle.api.publish.PublicationContainer) MavenPublication(org.gradle.api.publish.maven.MavenPublication) Jar(org.gradle.api.tasks.bundling.Jar)

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