I have a task whose single Output is a properties file:
public class PropertiesProviderTask extends DefaultTask {
@OutputFile
private RegularFileProperty output;
// ...
}
… and a consumer task that takes a String as input property:
public class ConsumerTask extends DefaultTask {
@Input
private Property<String> input;
// ...
}
I want to use one of the values within the provided property file as input for the consumer task and configure everything as lazily as possible.
task propertiesProvider(type: PropertiesProviderTask) {
// ...
}
task consumer(type: ConsumerTask) {
input = propertiesProvider.getOutput().map(propertiesFile -> {
Optional<String> value = retrieveProperty(propertiesFile, "property-key");
return value.orElse(null);
});
}
As far as I understand, Gradle should track the task reference and make consumer
automatically depend on propertiesProducer
, shouldn’t it?
The documentation on map
states:
When this provider represents a task or the output of a task, the new provider will be considered an output of the task and will carry dependency information that Gradle can use to automatically attach task dependencies to tasks that use the new provider for input values.
However, I’m getting the infamous:
Querying the mapped value of provider(java.util.Set) before task ‘:propertiesProvider’ has completed is not supported
unless I explicitly add:
consumer.dependsOn propertiesProducer
What am I doing wrong here?