How do I handle a configuration for publication with ivy-publish plugin with an artifact that may not exist?

I am currently trying to publish java artifacts to our Artifactory server using the ivy-publish plugin - I have a multi-project build containing all of the projects I want to publish. In the master build script, subprojects closure, I do some common configuration required for most of the subprojects:

publications {
             ivy(IvyPublication) {
                 // Jar file
                 from components.java
                                    // Extras
                 artifact(myOrMayNotExist) {
                    type "zip"
                    conf "extras"
                 }
             }
          }

The problem is that the “mayOrMayNotExist” task does not produce a zip file for all projects, which results in the following error when publishing:

Failed to publish publication ‘ivy’ to repository ‘ivy’

Invalid publication ‘ivy’: artifact file does not exist: ‘C:\FileThatMayOrMayNotExist.zip’

Is it possible to have an optional artifact like this? Or do I have to explicitly define this artifact in all the projects that do have it (as opposed to removing it in those that don’t)?

Thanks for any advice,

Tom

For anyone else looking at this thread, I’ve found a solution, even if it’s not particularly elegant. In the build.gradle file for each subproject that does not deliver the “extras”, we can explicitly remove them from the artifacts list using something like the code below:

publishing {
    publications {
        ivy(IvyPublication) {
            // This module has no extras, so we have to remove the artifact corresponding
            // to the zipped extras, or the publication fails
            def updatedArtifacts = [];
            artifacts.each {
                 if ( it.classifier != "extras" )
                  {
                    updatedArtifacts += it
                 }
            }
            artifacts = updatedArtifacts
        }
    }
}