Search in sources :

Example 1 with PublishingExtension

use of org.gradle.api.publish.PublishingExtension in project gradle by gradle.

the class ProjectDependencyPublicationResolver method resolve.

public ModuleVersionIdentifier resolve(ProjectDependency dependency) {
    Project dependencyProject = dependency.getDependencyProject();
    ((ProjectInternal) dependencyProject).evaluate();
    PublishingExtension publishing = dependencyProject.getExtensions().findByType(PublishingExtension.class);
    if (publishing == null || publishing.getPublications().withType(PublicationInternal.class).isEmpty()) {
        // Project does not apply publishing (or has no publications): simply use the project name in place of the dependency name
        return new DefaultModuleVersionIdentifier(dependency.getGroup(), dependencyProject.getName(), dependency.getVersion());
    }
    // See if all publications have the same identifier
    Set<? extends PublicationInternal> publications = publishing.getPublications().withType(PublicationInternal.class);
    Iterator<? extends PublicationInternal> iterator = publications.iterator();
    ModuleVersionIdentifier candidate = iterator.next().getCoordinates();
    while (iterator.hasNext()) {
        ModuleVersionIdentifier alternative = iterator.next().getCoordinates();
        if (!candidate.equals(alternative)) {
            throw new UnsupportedOperationException("Publishing is not yet able to resolve a dependency on a project with multiple different publications.");
        }
    }
    return candidate;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) Project(org.gradle.api.Project) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) PublishingExtension(org.gradle.api.publish.PublishingExtension)

Example 2 with PublishingExtension

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

the class SpringSigningPlugin method sign.

private void sign(Project project) {
    SigningExtension signing = project.getExtensions().findByType(SigningExtension.class);
    signing.setRequired(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return project.getGradle().getTaskGraph().hasTask("publishArtifacts");
        }
    });
    String signingKeyId = (String) project.findProperty("signingKeyId");
    String signingKey = (String) project.findProperty("signingKey");
    String signingPassword = (String) project.findProperty("signingPassword");
    if (signingKeyId != null) {
        signing.useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword);
    } else {
        signing.useInMemoryPgpKeys(signingKey, signingPassword);
    }
    project.getPlugins().withType(PublishAllJavaComponentsPlugin.class).all(new Action<PublishAllJavaComponentsPlugin>() {

        @Override
        public void execute(PublishAllJavaComponentsPlugin publishingPlugin) {
            PublishingExtension publishing = project.getExtensions().findByType(PublishingExtension.class);
            Publication maven = publishing.getPublications().getByName("mavenJava");
            signing.sign(maven);
        }
    });
}
Also used : SigningExtension(org.gradle.plugins.signing.SigningExtension) Publication(org.gradle.api.publish.Publication) PublishingExtension(org.gradle.api.publish.PublishingExtension)

Example 3 with PublishingExtension

use of org.gradle.api.publish.PublishingExtension 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 PublishingExtension

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

the class PublishLocalPlugin method apply.

@Override
public void apply(Project project) {
    project.getPlugins().withType(MavenPublishPlugin.class).all(new Action<MavenPublishPlugin>() {

        @Override
        public void execute(MavenPublishPlugin mavenPublish) {
            PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
            publishing.getRepositories().maven(new Action<MavenArtifactRepository>() {

                @Override
                public void execute(MavenArtifactRepository maven) {
                    maven.setName("local");
                    maven.setUrl(new File(project.getRootProject().getBuildDir(), "publications/repos"));
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) MavenPublishPlugin(org.gradle.api.publish.maven.plugins.MavenPublishPlugin) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) File(java.io.File) PublishingExtension(org.gradle.api.publish.PublishingExtension)

Example 5 with PublishingExtension

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

the class ConventionsPlugin method applyMavenConventions.

private void applyMavenConventions(Project project) {
    // J-
    // @formatter:off
    project.getPlugins().withType(MavenPublishPlugin.class, (mavenPublish) -> {
        PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
        publishing.getPublications().withType(MavenPublication.class).all((publication) -> {
            customizePom(publication.getPom(), project);
        });
    });
    project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> {
        JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
        extension.withJavadocJar();
        extension.withSourcesJar();
    });
// @formatter:on
// J+
}
Also used : 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

PublishingExtension (org.gradle.api.publish.PublishingExtension)16 Project (org.gradle.api.Project)8 JavaPlugin (org.gradle.api.plugins.JavaPlugin)8 Plugin (org.gradle.api.Plugin)7 MavenPublication (org.gradle.api.publish.maven.MavenPublication)7 JavaPlatformPlugin (org.gradle.api.plugins.JavaPlatformPlugin)5 MavenPublishPlugin (org.gradle.api.publish.maven.plugins.MavenPublishPlugin)5 Task (org.gradle.api.Task)4 File (java.io.File)3 Set (java.util.Set)3 Action (org.gradle.api.Action)3 HashMap (java.util.HashMap)2 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)2 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 ExtensionContainer (org.gradle.api.plugins.ExtensionContainer)2 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)2 SourceSet (org.gradle.api.tasks.SourceSet)2 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)2 TaskProvider (org.gradle.api.tasks.TaskProvider)2 IdlOptions (com.linkedin.pegasus.gradle.PegasusOptions.IdlOptions)1