static class Rules {
@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) {