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)); } }); }
@Mutate @SuppressWarnings("UnusedDeclaration") public void realizePublishingTasks(ModelMap<Task> tasks, PublishingExtension extension, @Path("buildDir") File buildDir) { // Create generatePom tasks for any Maven publication PublicationContainer publications = extension.getPublications(); Task publishLifecycleTask = tasks.get(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME); Task publishLocalLifecycleTask = tasks.get(PUBLISH_LOCAL_LIFECYCLE_TASK_NAME); for (final MavenPublicationInternal publication : publications.withType(MavenPublicationInternal.class)) { String publicationName = publication.getName(); createGeneratePomTask(tasks, publication, publicationName, buildDir); createLocalInstallTask(tasks, publishLocalLifecycleTask, publication, publicationName); createPublishTasksForEachMavenRepo(tasks, extension, publishLifecycleTask, publication, publicationName); } }
private void createPublishTasksForEachMavenRepo(ModelMap<Task> tasks, PublishingExtension extension, final Task publishLifecycleTask, final MavenPublicationInternal publication, final String publicationName) { for (final MavenArtifactRepository repository : extension.getRepositories().withType(MavenArtifactRepository.class)) { final String repositoryName = repository.getName(); String publishTaskName = "publish" + capitalize(publicationName) + "PublicationTo" + capitalize(repositoryName) + "Repository"; tasks.create(publishTaskName, PublishToMavenRepository.class, new Action<PublishToMavenRepository>() { public void execute(PublishToMavenRepository publishTask) { publishTask.setPublication(publication); publishTask.setRepository(repository); publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); publishTask.setDescription("Publishes Maven publication '" + publicationName + "' to Maven repository '" + repositoryName + "'."); } }); publishLifecycleTask.dependsOn(publishTaskName); } }
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; }
@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)); } }); }
private void createPublishTasksForEachMavenRepo(CollectionBuilder<Task> tasks, PublishingExtension extension, final Task publishLifecycleTask, final MavenPublicationInternal publication, final String publicationName) { for (final MavenArtifactRepository repository : extension.getRepositories().withType(MavenArtifactRepository.class)) { final String repositoryName = repository.getName(); String publishTaskName = String.format("publish%sPublicationTo%sRepository", capitalize(publicationName), capitalize(repositoryName)); tasks.create(publishTaskName, PublishToMavenRepository.class, new Action<PublishToMavenRepository>() { public void execute(PublishToMavenRepository publishTask) { publishTask.setPublication(publication); publishTask.setRepository(repository); publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); publishTask.setDescription(String.format("Publishes Maven publication '%s' to Maven repository '%s'.", publicationName, repositoryName)); //Because dynamic rules are not yet implemented we have to violate input immutability here as an interim step publishLifecycleTask.dependsOn(publishTask); } }); } }
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)); }
public void apply(final Project project) { RepositoryHandler repositories = publicationServices.createRepositoryHandler(); PublicationContainer publications = instantiator.newInstance(DefaultPublicationContainer.class, instantiator); // TODO Registering an extension should register it with the model registry as well project.getExtensions().create(PublishingExtension.NAME, DefaultPublishingExtension.class, repositories, publications); Task publishLifecycleTask = project.getTasks().create(PUBLISH_LIFECYCLE_TASK_NAME); publishLifecycleTask.setDescription("Publishes all publications produced by this project."); publishLifecycleTask.setGroup(PUBLISH_TASK_GROUP); }
@Mutate void addConfiguredPublicationsToProjectPublicationRegistry(ProjectPublicationRegistry projectPublicationRegistry, PublishingExtension extension, ProjectIdentifier projectIdentifier) { for (Publication publication : extension.getPublications()) { PublicationInternal internalPublication = (PublicationInternal) publication; projectPublicationRegistry.registerPublication(projectIdentifier.getPath(), new DefaultProjectPublication(internalPublication.getCoordinates())); } }
@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); }
@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); } }
@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); }
@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) { createIvyMarkerPublication(declaration, (IvyPublication) publications.getByName("pluginIvy"), publications); } }
public void apply(final Project project) { project.getPluginManager().apply(PublishingPlugin.class); // 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(IvyPublication.class, new IvyPublicationFactory(dependencyMetaDataProvider, instantiator, fileResolver)); } }); }
@Mutate @SuppressWarnings("UnusedDeclaration") public void createTasks(ModelMap<Task> tasks, PublishingExtension publishingExtension, @Path("buildDir") final File buildDir) { PublicationContainer publications = publishingExtension.getPublications(); RepositoryHandler repositories = publishingExtension.getRepositories(); for (final IvyPublicationInternal publication : publications.withType(IvyPublicationInternal.class)) { final String publicationName = publication.getName(); final String descriptorTaskName = "generateDescriptorFileFor" + capitalize(publicationName) + "Publication"; tasks.create(descriptorTaskName, GenerateIvyDescriptor.class, new Action<GenerateIvyDescriptor>() { public void execute(final GenerateIvyDescriptor descriptorTask) { descriptorTask.setDescription("Generates the Ivy Module Descriptor XML file for publication '" + publicationName + "'."); descriptorTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); descriptorTask.setDescriptor(publication.getDescriptor()); descriptorTask.setDestination(new File(buildDir, "publications/" + publicationName + "/ivy.xml")); } }); publication.setDescriptorFile(tasks.get(descriptorTaskName).getOutputs().getFiles()); for (final IvyArtifactRepository repository : repositories.withType(IvyArtifactRepository.class)) { final String repositoryName = repository.getName(); final String publishTaskName = "publish" + capitalize(publicationName) + "PublicationTo" + capitalize(repositoryName) + "Repository"; tasks.create(publishTaskName, PublishToIvyRepository.class, new Action<PublishToIvyRepository>() { public void execute(PublishToIvyRepository publishTask) { publishTask.setPublication(publication); publishTask.setRepository(repository); publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); publishTask.setDescription("Publishes Ivy publication '" + publicationName + "' to Ivy repository '" + repositoryName + "'."); } }); tasks.get(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).dependsOn(publishTaskName); } } }
public static List<DefaultMavenPublication> getMavenPublications(Project project) { List<DefaultMavenPublication> xdeps = new ArrayList<>(); PublishingExtension publishingExtension = getPublishingExtension(project); if (publishingExtension != null) { PublicationContainer publicationContainer = publishingExtension.getPublications(); for (Publication publication : publicationContainer) { xdeps.add((DefaultMavenPublication)publication); } } return xdeps; }
public static List<DefaultMavenArtifactRepository> getMavenRepositories(Project project) { List<DefaultMavenArtifactRepository> repos = new ArrayList<>(); PublishingExtension publishingExtension = getPublishingExtension(project); if (publishingExtension != null) { RepositoryHandler repositoryHandler = publishingExtension.getRepositories(); for (ArtifactRepository repo : repositoryHandler) { repos.add((DefaultMavenArtifactRepository)repo); } } return repos; }
@Mutate @SuppressWarnings("UnusedDeclaration") public void realizePublishingTasks(CollectionBuilder<Task> tasks, @Path("tasks.publish") Task publishLifecycleTask, @Path("tasks.publishToMavenLocal") Task publishLocalLifecycleTask, PublishingExtension extension) { // Create generatePom tasks for any Maven publication PublicationContainer publications = extension.getPublications(); for (final MavenPublicationInternal publication : publications.withType(MavenPublicationInternal.class)) { String publicationName = publication.getName(); createGeneratePomTask(tasks, publication, publicationName); createLocalInstallTask(tasks, publishLocalLifecycleTask, publication, publicationName); createPublishTasksForEachMavenRepo(tasks, extension, publishLifecycleTask, publication, publicationName); } }
public void apply(final Project project) { project.getPlugins().apply(PublishingPlugin.class); // 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(IvyPublication.class, new IvyPublicationFactory(dependencyMetaDataProvider, instantiator, fileResolver)); } }); }
@SuppressWarnings("UnusedDeclaration") public void realizePublishingTasks(TaskContainer tasks, PublishingExtension extension) { // Create generatePom tasks for any Maven publication PublicationContainer publications = extension.getPublications(); for (final MavenPublicationInternal publication : publications.withType(MavenPublicationInternal.class)) { String publicationName = publication.getName(); createGeneratePomTask(publication, publicationName); createLocalInstallTask(tasks, publication, publicationName); createPublishTasksForEachMavenRepo(tasks, extension, publication, publicationName); } }
private void createPublishTasksForEachMavenRepo(TaskContainer tasks, PublishingExtension extension, MavenPublicationInternal publication, String publicationName) { for (MavenArtifactRepository repository : extension.getRepositories().withType(MavenArtifactRepository.class)) { String repositoryName = repository.getName(); String publishTaskName = String.format("publish%sPublicationTo%sRepository", capitalize(publicationName), capitalize(repositoryName)); PublishToMavenRepository publishTask = tasks.create(publishTaskName, PublishToMavenRepository.class); publishTask.setPublication(publication); publishTask.setRepository(repository); publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); publishTask.setDescription(String.format("Publishes Maven publication '%s' to Maven repository '%s'.", publicationName, repositoryName)); publishLifecycleTask.dependsOn(publishTask); } }
public void createTasks(TaskContainer tasks, PublishingExtension publishingExtension) { PublicationContainer publications = publishingExtension.getPublications(); RepositoryHandler repositories = publishingExtension.getRepositories(); for (final IvyPublicationInternal publication : publications.withType(IvyPublicationInternal.class)) { final String publicationName = publication.getName(); final String descriptorTaskName = String.format("generateDescriptorFileFor%sPublication", capitalize(publicationName)); GenerateIvyDescriptor descriptorTask = tasks.create(descriptorTaskName, GenerateIvyDescriptor.class); descriptorTask.setDescription(String.format("Generates the Ivy Module Descriptor XML file for publication '%s'.", publication.getName())); descriptorTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); descriptorTask.setDescriptor(publication.getDescriptor()); ConventionMapping descriptorTaskConventionMapping = new DslObject(descriptorTask).getConventionMapping(); descriptorTaskConventionMapping.map("destination", new Callable<Object>() { public Object call() throws Exception { return new File(project.getBuildDir(), "publications/" + publication.getName() + "/ivy.xml"); } }); publication.setDescriptorFile(descriptorTask.getOutputs().getFiles()); for (IvyArtifactRepository repository : repositories.withType(IvyArtifactRepository.class)) { final String repositoryName = repository.getName(); final String publishTaskName = String.format("publish%sPublicationTo%sRepository", capitalize(publicationName), capitalize(repositoryName)); PublishToIvyRepository publishTask = tasks.create(publishTaskName, PublishToIvyRepository.class); publishTask.setPublication(publication); publishTask.setRepository(repository); publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); publishTask.setDescription(String.format("Publishes Ivy publication '%s' to Ivy repository '%s'.", publicationName, repositoryName)); tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).dependsOn(publishTask); } } }
public void apply(final Project project) { project.getPlugins().apply(PublishingPlugin.class); // 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(IvyPublication.class, new IvyPublicationFactory(dependencyMetaDataProvider, instantiator, fileResolver)); } }); modelRules.rule(new IvyPublicationTasksModelRule(project)); }
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); }
@Model PublishingExtension publishing(ExtensionContainer extensions) { return extensions.getByType(PublishingExtension.class); }
/** * 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); } }); } }
private static PublishingExtension getPublishingExtension(Project project) { return project.getExtensions().getByType(PublishingExtension.class); }
@Mutate @SuppressWarnings("UnusedDeclaration") public void createTasks(CollectionBuilder<Task> tasks, final @Path("tasks.publish") Task publishLifecycleTask, PublishingExtension publishingExtension) { PublicationContainer publications = publishingExtension.getPublications(); RepositoryHandler repositories = publishingExtension.getRepositories(); for (final IvyPublicationInternal publication : publications.withType(IvyPublicationInternal.class)) { final String publicationName = publication.getName(); final String descriptorTaskName = String.format("generateDescriptorFileFor%sPublication", capitalize(publicationName)); tasks.create(descriptorTaskName, GenerateIvyDescriptor.class, new Action<GenerateIvyDescriptor>() { public void execute(final GenerateIvyDescriptor descriptorTask) { descriptorTask.setDescription(String.format("Generates the Ivy Module Descriptor XML file for publication '%s'.", publication.getName())); descriptorTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); descriptorTask.setDescriptor(publication.getDescriptor()); ConventionMapping descriptorTaskConventionMapping = new DslObject(descriptorTask).getConventionMapping(); descriptorTaskConventionMapping.map("destination", new Callable<Object>() { public Object call() throws Exception { return new File(descriptorTask.getProject().getBuildDir(), "publications/" + publication.getName() + "/ivy.xml"); } }); publication.setDescriptorFile(descriptorTask.getOutputs().getFiles()); } }); for (final IvyArtifactRepository repository : repositories.withType(IvyArtifactRepository.class)) { final String repositoryName = repository.getName(); final String publishTaskName = String.format("publish%sPublicationTo%sRepository", capitalize(publicationName), capitalize(repositoryName)); tasks.create(publishTaskName, PublishToIvyRepository.class, new Action<PublishToIvyRepository>() { public void execute(PublishToIvyRepository publishTask) { publishTask.setPublication(publication); publishTask.setRepository(repository); publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); publishTask.setDescription(String.format("Publishes Ivy publication '%s' to Ivy repository '%s'.", publicationName, repositoryName)); //Because dynamic rules are not yet implemented we have to violate input immutability here as an interim step publishLifecycleTask.dependsOn(publishTask); } }); } } }
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; }