I apologize for cross posting from StackOverflow, but I didn’t seem to be getting any bites. I will update any answer I get there as well.
I am attempting to use the concepts described in the “Rule based model configuration” docs, and I am having trouble finding a path to do what I need.
I am using the ruleSourcePluginEach sample code to start with, but I need to be able to create a named task and dependOn it somewhere, for each FileItem and/or DirectoryItem.
As far as my limited knowledge of Gradle’s rule-based model can tell, there are 2 problems with your configuration:
Since the DirectoryRules rules are applied with scope (i.e. not applied to the root of the model as a plugin), you need to give it all model elements it needs access to. You haven’t given it the ModelMap<Task> tasks, so that’s the first problem. A potential solution would be:
It looks like Gradle’s @Each annotation can only be used on the target of a rule (i.e. the thing being modified), whereas you’re trying to use it on one of the rule’s inputs (the target is the ModelMap<Task> tasks). I don’t know why this restriction is applied to @Each; presumably it’s to do with when/how matching model objects are detected.
Without knowing exactly what you’re trying to achieve, it’s hard to suggest an ideal or idiomatic solution. However, naively, this seems to work: