public void apply(final Project project) { project.getPluginManager().apply(PublishingPlugin.class); final TaskContainer tasks = project.getTasks(); final Task publishLocalLifecycleTask = tasks.create(PUBLISH_LOCAL_LIFECYCLE_TASK_NAME); publishLocalLifecycleTask.setDescription("Publishes all Maven publications produced by this project to the local Maven cache."); publishLocalLifecycleTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); // Can't move this to rules yet, because it has to happen before user deferred configurable actions project.getExtensions().configure(PublishingExtension.class, new Action<PublishingExtension>() { public void execute(PublishingExtension extension) { // Register factory for MavenPublication extension.getPublications().registerFactory(MavenPublication.class, new MavenPublicationFactory(dependencyMetaDataProvider, instantiator, fileResolver)); } }); }
private void createMavenMarkerPublication(PluginDeclaration declaration, final MavenPublication coordinates, PublicationContainer publications) { String pluginId = declaration.getId(); MavenPublication publication = publications.create(declaration.getName() + "PluginMarkerMaven", MavenPublication.class); 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()); } }); }
@Override public void apply(Project project) { this.project = project; project.getPlugins().apply(getPluginClass()); project.getPlugins().apply(MavenPublishPlugin.class); publication = project.getExtensions().getByType(PublishingExtension.class) .getPublications() .create(getPublicationName(), MavenPublication.class); publication.from(getSoftwareComponent()); project.getPlugins().withType(SourcesJarPlugin.class, sourcesJarPlugin -> publication.artifact(sourcesJarPlugin.getJarTask(), a -> a.setClassifier(sourcesJarPlugin.getClassifier())) ); project.getPlugins().withType(JavadocJarPlugin.class, javadocJarPlugin -> publication.artifact(javadocJarPlugin.getJarTask(), a -> a.setClassifier(javadocJarPlugin.getClassifier())) ); }
public void apply(final Project project) { project.getPlugins().apply(PublishingPlugin.class); final TaskContainer tasks = project.getTasks(); final Task publishLocalLifecycleTask = tasks.create(PUBLISH_LOCAL_LIFECYCLE_TASK_NAME); publishLocalLifecycleTask.setDescription("Publishes all Maven publications produced by this project to the local Maven cache."); publishLocalLifecycleTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); // Can't move this to rules yet, because it has to happen before user deferred configurable actions project.getExtensions().configure(PublishingExtension.class, new Action<PublishingExtension>() { public void execute(PublishingExtension extension) { // Register factory for MavenPublication extension.getPublications().registerFactory(MavenPublication.class, new MavenPublicationFactory(dependencyMetaDataProvider, instantiator, fileResolver)); } }); }
public void apply(final Project project) { project.getPlugins().apply(PublishingPlugin.class); final TaskContainer tasks = project.getTasks(); final Task publishLifecycleTask = tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME); final Task publishLocalLifecycleTask = tasks.create(PUBLISH_LOCAL_LIFECYCLE_TASK_NAME); publishLocalLifecycleTask.setDescription("Publishes all Maven publications produced by this project to the local Maven cache."); publishLocalLifecycleTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); // Can't move this to rules yet, because it has to happen before user deferred configurable actions project.getExtensions().configure(PublishingExtension.class, new Action<PublishingExtension>() { public void execute(PublishingExtension extension) { // Register factory for MavenPublication extension.getPublications().registerFactory(MavenPublication.class, new MavenPublicationFactory(dependencyMetaDataProvider, instantiator, fileResolver)); } }); modelRules.rule(new MavenPublishTaskModelRule(project, publishLifecycleTask, publishLocalLifecycleTask)); }
private static MavenPublicationInternal toPublicationInternal(MavenPublication publication) { if (publication == null) { return null; } else if (publication instanceof MavenPublicationInternal) { return (MavenPublicationInternal) publication; } else { throw new InvalidUserDataException( String.format( "publication objects must implement the '%s' interface, implementation '%s' does not", MavenPublicationInternal.class.getName(), publication.getClass().getName() ) ); } }
public MavenPublication create(final String name) { Module module = dependencyMetaDataProvider.getModule(); MavenProjectIdentity projectIdentity = new DefaultMavenProjectIdentity(module.getGroup(), module.getName(), module.getVersion()); NotationParser<Object, MavenArtifact> artifactNotationParser = new MavenArtifactNotationParserFactory(instantiator, fileResolver).create(); return instantiator.newInstance( DefaultMavenPublication.class, name, projectIdentity, artifactNotationParser, instantiator, projectDependencyResolver, fileCollectionFactory ); }
@Finalize public void addMarkerPublications(PublishingExtension publishing, GradlePluginDevelopmentExtension pluginDevelopment) { if (!pluginDevelopment.isAutomatedPublishing()) { return; } PublicationContainer publications = publishing.getPublications(); NamedDomainObjectContainer<PluginDeclaration> declaredPlugins = pluginDevelopment.getPlugins(); for (PluginDeclaration declaration : declaredPlugins) { createMavenMarkerPublication(declaration, (MavenPublication) publications.getByName("pluginMaven"), publications); } }
/** * Customizes the pom. The method requires following properties on root project to function correctly: */ public static void customizePom(final Project project, final ShipkitConfiguration conf, final MavenPublication publication) { publication.getPom().withXml(new Action<XmlProvider>() { public void execute(XmlProvider xml) { String archivesBaseName = (String) project.getProperties().get("archivesBaseName"); File contributorsFile = contributorsFile(project); LOG.info(" Read project contributors from file: " + contributorsFile.getAbsolutePath()); // It can happens that contributorsFile doesn't exist e.g. when shipkit.team.contributors is NOT empty ProjectContributorsSet contributorsFromGitHub = new ProjectContributorsSerializer() .deserialize(IOUtil.readFullyOrDefault(contributorsFile, "[]")); LOG.info(" Customizing pom for publication " + publication.getName() + " in " + project.toString() + "\n - Module name (project.archivesBaseName): " + archivesBaseName + "\n - Description (project.description): " + project.getDescription() + "\n - GitHub repository (project.rootProject.shipkit.gitHub.repository): " + conf.getGitHub().getRepository() + "\n - Developers (project.rootProject.shipkit.team.developers): " + StringUtil.join(conf.getTeam().getDevelopers(), ", ") + "\n - Contributors (project.rootProject.shipkit.team.contributors): " + StringUtil.join(conf.getTeam().getContributors(), ", ") + "\n - Contributors read from GitHub: " + StringUtil.join(contributorsFromGitHub.toConfigNotation(), ", ")); customizePom(xml.asNode(), conf, archivesBaseName, project.getDescription(), contributorsFromGitHub); } }); }
public MavenPublication create(final String name) { Module module = dependencyMetaDataProvider.getModule(); MavenProjectIdentity projectIdentity = new DefaultMavenProjectIdentity(module.getGroup(), module.getName(), module.getVersion()); NotationParser<Object, MavenArtifact> artifactNotationParser = new MavenArtifactNotationParserFactory(instantiator, fileResolver).create(); return instantiator.newInstance( DefaultMavenPublication.class, name, projectIdentity, artifactNotationParser, instantiator, projectDependencyResolver ); }
private static @Nullable MavenPublication findMainPublication(Project project) { ensureMavenPublishPlugin(project); val publishing = project.getConvention().getByType(PublishingExtension.class); val publications = publishing.getPublications(); return (MavenPublication)publications.findByName(PUBLICATION_NAME); }
private void registerArtifacts(Project project, MavenPublication publication) { val mainJarTask = (Jar)project.getTasks().getByName("jar"); addArtifactToPublication(publication, mainJarTask); addArtifactToArchives(project, mainJarTask); addArtifactToPublication(publication, sourcesJarTask(project)); addArtifactToArchives(project, sourcesJarTask(project)); val docJarTask = docJarTask(project); if (docJarTask != null) { addArtifactToPublication(publication, docJarTask); addArtifactToArchives(project, docJarTask); } }
private static void addArtifactToPublication(MavenPublication publication, Jar jarTask) { val hasArtifactAlready = publication.getArtifacts(). stream(). anyMatch(artifact -> jarTask.getOutputs().getFiles().contains(artifact.getFile())); if (!hasArtifactAlready) { publication.artifact(jarTask); } }
private void createMavenPluginPublication(SoftwareComponent component, PublicationContainer publications) { MavenPublication publication = publications.create("pluginMaven", MavenPublication.class); publication.from(component); }
/** * Create the default Maven publication * * @param publishingExtension Publishing extension where the publication is created * @param projectContext Project context to access project information * @param projectConfig Project configuration * @param mavenConfig Maven configuration * @param configurations Container to access configurations * @param services Service manager to obtain service objects */ @Mutate public void createPublications(PublishingExtension publishingExtension, ProjectContext projectContext, ProjectConfig projectConfig, MavenConfig mavenConfig, ConfigurationContainer configurations, ServiceRegistry services) { SoftwareComponentContainer components = services.get(SoftwareComponentContainer.class); JavaLibrary javaComponent = components.withType(JavaLibrary.class).getByName("java"); for (MavenPublicationConfig publicationConfig : mavenConfig.getPublications()) { Configuration configuration = configurations .getByName(publicationConfig.getArchivesConfiguration()); publishingExtension.getPublications().create(publicationConfig.getName(), MavenPublication.class, p -> { p.setArtifactId(publicationConfig.getArtifactId()); List<@NonNull Configuration> runtimeConfigurations = publicationConfig .getRuntimeConfigurations().stream().map(c -> configurations.getByName(c)) .collect(Collectors.toList()); List<@NonNull Configuration> compileConfigurations = publicationConfig .getCompileConfigurations().stream().map(c -> configurations.getByName(c)) .collect(Collectors.toList()); List<@NonNull PublishArtifact> artifacts = Collections.emptyList(); if (publicationConfig.isAddProjectArtifacts()) { artifacts = javaComponent.getUsages().stream() .flatMap(u -> u.getArtifacts().stream()).collect(Collectors.toList()); } PomConfigurator configurator = new PomConfigurator(projectContext, projectConfig, Validate.notNull(runtimeConfigurations), Validate.notNull(compileConfigurations)); p.pom(pom -> pom.withXml(xml -> configurator.configurePom(Validate.notNull(xml)))); for (PublishArtifact a : configuration.getArtifacts()) { p.artifact(a); } }); } }
/** * Gets (creating, if needed) the "main" publication. */ public static MavenPublication mainPublication(Project project) { val pub = findMainPublication(project); return (pub == null) ? createMainPublication(project) : pub; }
private static void configPom(Project project, MavenPublication pub) { pub.pom(pom -> pom.withXml(xmlProvider -> configPom(project, xmlProvider))); }
private static MavenPublication createMainPublication(Project project) { val publishing = project.getConvention().getByType(PublishingExtension.class); val pub = publishing.getPublications().create(PUBLICATION_NAME, MavenPublication.class); publishing.getRepositories().mavenLocal(); project.afterEvaluate(prj -> groupid(project, (MavenPomInternal)pub.getPom())); configPom(project, pub); return pub; }
/** * The publication to be published. * * @return The publication to be published */ @Internal public MavenPublication getPublication() { return publication; }
/** * Sets the publication to be published. * * @param publication The publication to be published */ public void setPublication(MavenPublication publication) { this.publication = toPublicationInternal(publication); }
/** * The publication to be published. * * @return The publication to be published */ public MavenPublication getPublication() { return publication; }