Upload custom artifact using maven-publish

As part of the build process I need to generate a text file that contains metadata about the artifacts generated. This file needs to be uploaded to Nexus using the maven-publish plugin. I have a task that generates this file and writes to the build directory of the project. I’d prefer to tell maven-publish to get the artifact of the task instead of a path to the where the file exists. That way the task will always run during publish.

Is it possible to specify a file generated in a task as an artifact?

publishing {
    publications {
        txt(MavenPublication) {
            groupId group
            artifactId 'inventory'
            artifact file("buildDir/inventory.txt")  // This works, but does not make publish dependent on buildTxt
            // artifact buildTxt  // This is ideal

task buildTxt() << {
    def txtFile = new File("$buildDir/inventory.txt")
    // Write text to txtFile