I tried to add additional artifacts to a publication and I used the model space to solve my issue.
Therefore I added a static class to my plugin:
static class Rules extends RuleSource { @Mutate public static void configurePublishingPublications(ModelMap<Task> tasks, final PublishingExtension publishing, FileCollection files) { IvyPublication ivyPub = publications.create("myPub", IvyPublication.class, ivyPublication -> { for(ZipComponent task : tasks.withType(ZipComponent.class).values()) { ivyPublication.artifact(task, ivyArtifact -> { // configuration } } }); } }
If I run a test, it seems that the publishing has no input and my tasks artifacts are ignored. I checked the model:
+ tasks | Type: org.gradle.model.ModelMap<org.gradle.api.Task> | Creator: Project.<init>.tasks() | Rules: ⤷ PublishingPlugin.Rules#tasksDependOnProjectPublicationRegistry(ModelMap<Task>, ProjectPublicationRegistry) ⤷ IvyPublishPlugin.Rules#createTasks(ModelMap<Task>, PublishingExtension, File) ⤷ CartridgePlugin.Rules#configurePublishingPublications(ModelMap<Task>, PublishingExtension, FileCollection)
I tried to change the order of rules. TherforeI changed the order of parameters for the method configurePublishingPublications and I got an exception.
After that I change Mutate to Defaults und now it works!
+ tasks | Type: org.gradle.model.ModelMap<org.gradle.api.Task> | Creator: Project.<init>.tasks() | Rules: ⤷ CartridgePlugin.Rules#configurePublishingPublications(ModelMap<Task>, PublishingExtension, FileCollection) ⤷ PublishingPlugin.Rules#tasksDependOnProjectPublicationRegistry(ModelMap<Task>, ProjectPublicationRegistry) ⤷ IvyPublishPlugin.Rules#createTasks(ModelMap<Task>, PublishingExtension, File)
But is this the correct way?