public void from(SoftwareComponent component) { if (this.component != null) { throw new InvalidUserDataException(String.format("Maven publication '%s' cannot include multiple components", name)); } this.component = (SoftwareComponentInternal) component; for (Usage usage : this.component.getUsages()) { // TODO Need a smarter way to map usage to artifact classifier for (PublishArtifact publishArtifact : usage.getArtifacts()) { artifact(publishArtifact); } // TODO Need a smarter way to map usage to scope for (ModuleDependency dependency : usage.getDependencies()) { if (dependency instanceof ProjectDependency) { addProjectDependency((ProjectDependency) dependency); } else { addModuleDependency(dependency); } } } }
@TaskAction protected void deployProject() { Set<PublishArtifact> seenArtifacts = new HashSet<>(); for ( SoftwareComponent component : getProject().getComponents() ) { SoftwareComponentInternal internalComponent = (SoftwareComponentInternal) component; for ( UsageContext usage : internalComponent.getUsages() ) { Set<? extends ModuleDependency> dependencies = usage.getDependencies(); for ( PublishArtifact artifact : usage.getArtifacts() ) { if ( seenArtifacts.add( artifact ) ) { deploy( artifact, dependencies ); } } } } }
@Mutate public void addMainPublication(PublishingExtension publishing, GradlePluginDevelopmentExtension pluginDevelopment, ServiceRegistry services) { if (!pluginDevelopment.isAutomatedPublishing()) { return; } SoftwareComponentContainer componentContainer = services.get(SoftwareComponentContainer.class); SoftwareComponent component = componentContainer.getByName("java"); PublicationContainer publications = publishing.getPublications(); createMavenPluginPublication(component, publications); }
@Mutate public void addMainPublication(PublishingExtension publishing, GradlePluginDevelopmentExtension pluginDevelopment, ServiceRegistry services) { if (!pluginDevelopment.isAutomatedPublishing()) { return; } SoftwareComponentContainer componentContainer = services.get(SoftwareComponentContainer.class); SoftwareComponent component = componentContainer.getByName("java"); PublicationContainer publications = publishing.getPublications(); createIvyPluginPublication(component, publications); }
public void from(SoftwareComponent component) { if (this.component != null) { throw new InvalidUserDataException(String.format("Ivy publication '%s' cannot include multiple components", name)); } this.component = (SoftwareComponentInternal) component; configurations.maybeCreate("default"); for (Usage usage : this.component.getUsages()) { String conf = usage.getName(); configurations.maybeCreate(conf); configurations.getByName("default").extend(conf); for (PublishArtifact publishArtifact : usage.getArtifacts()) { artifact(publishArtifact).setConf(conf); } for (ModuleDependency dependency : usage.getDependencies()) { // TODO: When we support multiple components or configurable dependencies, we'll need to merge the confs of multiple dependencies with same id. String confMapping = String.format("%s->%s", conf, dependency.getTargetConfiguration() == null ? Dependency.DEFAULT_CONFIGURATION : dependency.getTargetConfiguration()); if (dependency instanceof ProjectDependency) { addProjectDependency((ProjectDependency) dependency, confMapping); } else { addModuleDependency(dependency, confMapping); } } } }
public void from(SoftwareComponent component) { if (this.component != null) { throw new InvalidUserDataException(String.format("Ivy publication '%s' cannot include multiple components", name)); } this.component = (SoftwareComponentInternal) component; configurations.maybeCreate("default"); for (Usage usage : this.component.getUsages()) { String conf = usage.getName(); configurations.maybeCreate(conf); configurations.getByName("default").extend(conf); for (PublishArtifact publishArtifact : usage.getArtifacts()) { artifact(publishArtifact).setConf(conf); } for (ModuleDependency dependency : usage.getDependencies()) { // TODO: When we support multiple components or configurable dependencies, we'll need to merge the confs of multiple dependencies with same id. String confMapping = String.format("%s->%s", conf, dependency.getConfiguration()); if (dependency instanceof ProjectDependency) { addProjectDependency((ProjectDependency) dependency, confMapping); } else { addModuleDependency(dependency, confMapping); } } } }
private void createMavenPluginPublication(SoftwareComponent component, PublicationContainer publications) { MavenPublication publication = publications.create("pluginMaven", MavenPublication.class); publication.from(component); }
private void createIvyPluginPublication(SoftwareComponent component, PublicationContainer publications) { IvyPublication publication = publications.create("pluginIvy", IvyPublication.class); publication.from(component); }
public SoftwareComponent getSoftwareComponent() { return getProject().getComponents().getByName(getComponentName()); }
/** * Provides the software component that should be published. * * <ul> * <li>Any artifacts declared by the component will be included in the publication.</li> * <li>The dependencies declared by the component will be included in the published meta-data.</li> * </ul> * * Currently 2 types of component are supported: 'components.java' (added by the JavaPlugin) and 'components.web' (added by the WarPlugin). * For any individual MavenPublication, only a single component can be provided in this way. * * The following example demonstrates how to publish the 'java' component to a Maven repository. * <pre autoTested="true"> * apply plugin: "java" * apply plugin: "maven-publish" * * publishing { * publications { * maven(MavenPublication) { * from components.java * } * } * } * </pre> * * @param component The software component to publish. */ void from(SoftwareComponent component);
/** * Provides the software component that should be published. * * <ul> * <li>Any artifacts declared by the component will be included in the publication.</li> * <li>The dependencies declared by the component will be included in the published meta-data.</li> * </ul> * * Currently 2 types of component are supported: 'components.java' (added by the JavaPlugin) and 'components.web' (added by the WarPlugin). * For any individual IvyPublication, only a single component can be provided in this way. * * The following example demonstrates how to publish the 'java' component to a ivy repository. * <pre autoTested="true"> * apply plugin: "java" * apply plugin: "ivy-publish" * * publishing { * publications { * ivy(IvyPublication) { * from components.java * } * } * } * </pre> * * @param component The software component to publish. */ void from(SoftwareComponent component);