Publishing task output to ivy

I need to publish the output of a task to Ivy, and I can’t find how to:

  1. create a dependency on the task generating the file in the publishing step
  2. add a specific file to the publishing step

I’m using Gradle 2.11, and publishing the output from a tar task works as expected:

apply plugin: 'ivy-publish'

publishing {
    repositories {
        ivy {
            url ivyRepoUrl // defined elsewhere
        }
    }
}

publishing {
    publications {
        ivy(IvyPublication) {
            // tarTask is defined elsewhere
            module tarTask.baseName
            artifact(tarTask) {
                name tarTask.baseName
                extension 'xcarchive.tgz'
            }
        }
    }
}

Now I want to do the same thing with the output from a non-archive (tar/zip) task:

publishing {
    publications {
        ivy(IvyPublication) {
            // fooTask is defined elsewhere
            module fooTask.moduleName
            artifact(fooTask) {
                name fooTask.moduleName
                extension 'ipa'
            }
        }
    }
}

Please ignore the fact that an iOS ipa is in fact a zip file, as the generation is done outside of Gradle in my case, so I don’t have an actual zip task for it, just an Exec task which makes the ipa appear.

Specifying artifact(fooTask.ipaFile) works in the sense that it tries to publish the right file, but it doesn’t add fooTask as a dependency to publishing, so the build will fail on a missing file.

There were a few older questions about this, but they were specifically referring to Maven and POM manipulation (I need to use Ivy), and were also several years old.

After much digging and mixing of the docs for old and new-style publishing, I believe that adding builtBy fooTask to my second artifact solves the problem.