问题
SOLVED - see the end of this post.
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?
NOTE: I'm attempting to follow the publishing solution from (the accepted answer to) Upload an RPM to Artifactory from Gradle
SOLUTION: According to the Gradle documentation, there should be a [originalname] built-in pattern available, but it doesn't seem to be implemented. As a workaround, override and then use the [module] pattern as follows:
def rpmFile = tasks."buildRpm_${hostId}".outputs.getFiles().getSingleFile()
publishing.publications.create("${project.name}-${hostId}", IvyPublication) {
artifact rpmFile
module rpmFile.getName()
}
And then your publishing section should look like this:
publishing {
repositories {
ivy {
credentials {
username "${citiEarUser}"
password "${citiEarPassword}"
}
url "${yumRepo}"
layout 'pattern', {
artifact "[module]"
}
}
}
}
回答1:
Since, the [originalname]
placeholder is not implemented yet, you could use another placeholder to provide the file name for your custom pattern:
publishing {
publications {
myPub(IvyPublication) {
artifact myFile
module myFile.name
organisation 'myOrg' // required for some unknown reason
}
}
repositories {
ivy {
url myUrl
layout 'pattern', {
artifact '[module]'
}
}
}
}
来源:https://stackoverflow.com/questions/48812467/how-do-i-de-reference-a-collection-of-gradle-publications