Sharing single file output between projects for use as input to Task InputFile

I have been following the procedure described in the documentation here for sharing files between projects. However I would like to know what the proper way to use the file is in the consuming project when the dependency needs to be passed to the input of a Task.

I have the following sample files to illustrate my question. I have a producer project projectA with the following build.gradle:

abstract class ProducerTask extends DefaultTask {
    @OutputFile
    final RegularFileProperty file = project.objects.fileProperty()

    @TaskAction
    def execute() {
        file.get().asFile.setText("file content")
    }
}

configurations {
    producer {
        canBeConsumed = true
        canBeResolved = false
    }
}

tasks.register('createFile', ProducerTask) {
    file.set new File(projectDir, "file.txt")
}

artifacts {
    producer createFile.file
}

And the following consuming project projectB with its build.gradle file:

abstract class ConsumerTask extends DefaultTask {
    @InputFile
    final RegularFileProperty file = project.objects.fileProperty()

    @TaskAction
    def execute() {
        println("Text: " + file.get().asFile.getText())
    }
}

configurations {
    consumer {
        canBeConsumed = false
        canBeResolved = true
    }
}

dependencies {
    consumer project(path: ":projectA", configuration: 'producer')
}

tasks.register('consumeFile', ConsumerTask) {
    file.fileProvider(providers.provider { configurations.consumer.singleFile })
}

Project A creates a file with some text in it with the ProducerTask. Project B uses this file in the ConsumerTask. I have set it up following the description in the documention.

My question is related to the line in the consumeFile task: file.fileProvider(providers.provider { configurations.consumer.singleFile }). Is this how the single file artifact should be passed onto the task as input?

I noticed I need to add dependsOn configurations.consumer to the consumeFile task, to make gradle understand the dependency of consumeFile on createFile. Is there a different way of constructing the consumeFile task so gradle can determine this dependency automatically?