Dereference a collection of publications

When publishing Ivy publications individually, how can I then reference the collection in my subprojects section?

I’m working with tasks that build rpms inside a nested iteration - they look a bit like this:

def addWebServerTasks(aProject, hostId) {
    aProject.with {
        task "buildRpm_${hostId}"(type: Rpm, dependsOn: "templates_${hostId}") {
        ...
        }
        publishing.publications.create("${project.name}-${hostId}", IvyPublication) {
            artifact tasks."buildRpm_${hostId}".outputs.getFiles().getSingleFile()
        }
    }
}

This creates 8 RPMS with filenames in the format: subproject-env-region-hostname-version_branchname.rpm. Here’s a sample:

web-server-config-DEV-EMEA-dev.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm
web-server-config-UAT-EMEA-uat.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm
web-server-config-UAT-APAC-uat.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm
web-server-config-PROD-APAC-prod1.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm
web-server-config-PROD-APAC-prod2.server.com-1.1.0_feature_yum_upload_SNAPSHOT.noarch.rpm

I have declared a repository to publish to as below, but the URL it’s trying to upload to does not match the RPM name.

subprojects {
    publishing {
        repositories {
            ivy {
                credentials {
                    username yumDeployUser
                    password yumDeployPassword
                }
                url yumRepo
            }
        }
    }
}

For each RPM, I can see output like the following, where the RPM file name is not the same as the one created on the filesystem - in fact, for all of the above RPMs, it tries to upload to the same path.

:web-server-config:generateDescriptorFileForWeb-server-config-DEV-EMEA-dev.server.comPublication
:web-server-config:publishWeb-server-config-DEV-EMEA-dev.server.comPublicationToIvyRepository
Upload https://artifactrepository/artifactory/yum/foo/myproject/web-server-config/1.1.0-feature_yum-upload-SNAPSHOT/web-server-config-1.1.0-feature_yum-upload-SNAPSHOT.rpm

What’s missing is the “env-region-hostname” part of the filename. Why is this being dropped? Or is there some other reason the actual artifact names are not being passed to the Ivy Publisher?

Ok, managed to discover the secret is to use a pattern layout for artifacts with the keyword “module”, and then configure “module” explicitly in the publication(s).

Publication:

    def rpmFile = tasks."buildRpm_${hostId}".outputs.getFiles().getSingleFile()
    publishing.publications.create("${project.name}-${hostId}", IvyPublication) {
        artifact rpmFile
        module rpmFile.getName()
    }

Repository:

publishing {
    repositories {
        ivy {
            credentials {
                username yumDeployUser
                password yumDeployPassword
            }
            url yumRepo
            layout 'pattern', {
                artifact "[module]"
            }
        }
    }
}