I’m attempting to implement a protostuff plugin that allows a project to have n proto files, configure the protostuff compiler for each independently and have them execute ahead of (java) compilation. Ideally they’d only fire if the proto had changed.
To support the “configure the compiler on a per proto basis” requirement, I was going to create a container and expose that as an extension. For example
The problem I have is with the incremental compilation requirement. It seems I’d need to break down the extensions into a task per entry in the container and specify the ‘@Input’ for each one but I don’t know how to do that. Any guidance would be v helpful.
There’s a ‘project.container’ variant that allows you to specify a factory. Use this to inject the ‘Project’ into the ‘ProtoModule’ and create the task in there. So in essence you are making ProtoModule a task wrapper.
A better option though would be to use a configuration rule on the ‘protos’ container.
with the same build.gradle snippet from the earlier post. It seems the rule fires before the named object has been put into the container hence getByName fails so this blows. Am I doing something wrong or do I have to lazily lookup the named domain object?
I wouldn’t use ‘addRule’, I’d use ‘all’ which has a different function.
‘addRule’ is less useful for auto-vivifying containers (which this one is). You need to specify that modules should be created on demand, you need to specify that a task should be created for each created module which is what ‘all’ is for.
I hadn’t noticed that add covers all things added in future too, that’s much cleaner.
I’m back at the chicken and egg problem though as it seems that the ProtoModule instance is not fully configured at the point at which it is seen by the add action.
The reason I think I need this is because I need to choose which task to configure based on a certain property on the ProtoModule object.
There is an attribute of ProtoModule that determines the task, I have 1 impl that extends JavaExec because I have to fork to a fresh jvm and another that executes the required code inline. The tasks are my own.