The intention to have a Provider<RegularFile> is not to have a modifiable property that is accessible for a task consumer (these tasks are part of a plugin).
As far as I checked, in both examples it is possible to attempt to set that property and both will fail due
to disallowChanges not due to that the the fact that there is no property to modify.
But this might just do , unless anything else comes to your mind.
Being a curious beast and trying to better understand how lazy-configuration works, what is the general reason why my initial attemp was not working ? (unless this is too complex to explain failry briefly).
I’m not fully sure.
Afair, the implicit dependencies only work on Propertys, not on Providers.
Whether this is intended, or a missing feature I don’t know.
For example this works:
final RegularFileProperty outputFile = objects.fileProperty()
while this does not:
final Provider<RegularFile> outputFile = objects.fileProperty()
This also works:
final RegularFileProperty outputFile = objects.fileProperty().value(getOutputFileName().flatMap(name -> project.layout.buildDirectory.file(name)))
while the same with Provider<RegularFile> does not work.
As well as the following which is also not working:
final RegularFileProperty outputFile = objects.fileProperty().value(getOutputFileName().flatMap(name -> project.layout.buildDirectory.file(name))).disallowChanges()
Maybe this get changed if someone posts a feature request, I don’t know.
Or maybe you could at least request a more in-depth documentation on what is necessary that it works.
With the solution that splits outputFile provider and property, the consumer should not actually use the property anyway, as it is protected, or you can also make it package-private.
The problem is, that with a Groovy consumer, he can still access it as you can even access private properties with Groovy without further ado.