I am trying to publish artifacts using the new ivy publishing plugin, but I’m having trouble however because it resolves the filename of artifact in the configuration phase, but I change that value in a gradle.taskGraph.whenReady closure. More specifically - the version number changes depending on what task is being run/command line properties set. The war task uses the correct value when generating the archives, but the publishing stuff ends up complaining that it cannot find the archive ‘xxx-unspecified.war’.
Is there any way I can use the publishing plugin to do what I want or do I have to push things to our ivy repo in a different way?
For reference: gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(release)) {
loadProperties ‘release.properties’ // just reads the properties from the file and calls ext[property.key] = property.value
version = project.releaseVersion
} else {
if (project.hasProperty(‘buildNumber’)) {
version = project.buildNumber
} else {
version = ‘DEV’
}
} }
There are some known problems with the current configuration mechanism for publications. I’d try to set ‘publishing.publications.publicationName.revision’ from inside ‘whenReady’.
That helped, but only after I messed with the publication artifacts (and upgraded to 1.7 - I was on 1.6). The issue is that the artifacts that are added to the publication during the configuration phase have their file property set at that time. Because I am changing the version number after this happens (in ‘whenReady’), the file generated by the war task has a different name than the one set in the artifact - so the plugin cannot find it when it tries to upload it.
I finally managed to make it work by calling ‘publishing.publications.publicationName.artifacts.clear()’ in the ‘whenReady’ and then in the doLast of the war I build a ‘DefaultIvyArtifact’ with the correct file and call ‘publishing.publications.publicationName.artifacts.add’ with the new artifact (yeah - I know DefaultIvyArtifact is an internal class, but I’m too lazy to reimplement the interface in my build file).