Search in sources :

Example 1 with DomainObjectSet

use of org.gradle.api.DomainObjectSet in project gradle by gradle.

the class NativeBasePlugin method addPublicationsFromVariants.

private void addPublicationsFromVariants(final Project project, final SoftwareComponentContainer components) {
    project.getPluginManager().withPlugin("maven-publish", plugin -> {
        components.withType(PublicationAwareComponent.class, component -> {
            project.getExtensions().configure(PublishingExtension.class, publishing -> {
                final ComponentWithVariants mainVariant = component.getMainPublication();
                publishing.getPublications().create("main", MavenPublication.class, publication -> {
                    MavenPublicationInternal publicationInternal = (MavenPublicationInternal) publication;
                    publicationInternal.getMavenProjectIdentity().getArtifactId().set(component.getBaseName());
                    publicationInternal.from(mainVariant);
                    publicationInternal.publishWithOriginalFileName();
                });
                Set<? extends SoftwareComponent> variants = mainVariant.getVariants();
                if (variants instanceof DomainObjectSet) {
                    ((DomainObjectSet<? extends SoftwareComponent>) variants).all(child -> addPublicationFromVariant(child, publishing, project));
                } else {
                    for (SoftwareComponent variant : variants) {
                        addPublicationFromVariant(variant, publishing, project);
                    }
                }
            });
        });
    });
}
Also used : ComponentWithVariants(org.gradle.api.component.ComponentWithVariants) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) SoftwareComponent(org.gradle.api.component.SoftwareComponent) DomainObjectSet(org.gradle.api.DomainObjectSet)

Aggregations

DomainObjectSet (org.gradle.api.DomainObjectSet)1 ComponentWithVariants (org.gradle.api.component.ComponentWithVariants)1 SoftwareComponent (org.gradle.api.component.SoftwareComponent)1 MavenPublicationInternal (org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal)1