It's never too late to answer a question about SO, so ...
I encountered very similar complications during one of the tasks at work.
And I was able to solve it.
Short version
All you need to know about the generated moduleB module classes in moduleA is the name of the package and class. This can be saved as a MyClassesRegistrar generated class, placed in a well-known package. Use suffixes to avoid name conflicts, get registrars by packages. Create them and use the data from them.
version of lond
First of all - you CANNOT turn on only compilation-dependent time only in the very top module (allows you to call this "application" module, as your typical Android project structure does). Annotation processing doesn't work that way, and as far as I can tell, there's nothing to be done.
Now to the details. My task was as follows: I have annotated classes written by man. I will call them "events." At compile time, I need to create helper classes for these events in order to include their structure and content (both statically accessible (annotation values, constants, etc.), and runtime (I pass event objects to these helpers when using the latter). the class name depends on the class name of the event with a suffix, so I do not know it until the code generation is complete.
So, after creating the helpers, I create a factory and generate code to provide a new helper instance based on MyEvent.class . Here's the problem: I need only one factory in the application module, but it should be able to provide helpers for events from the library module - this cannot be done simply.
What I've done:
skip creating a factory for the modules my application module depends on;
in modules other than the application, generates the so-called HelpersRegistrar implementation (s):
- they all use the same package (you will find out why later);
- their names do not collide due to a suffix (see below);
- differentiation between the application module and the library module is performed using javac "-Amylib.suffix=MyModuleName" param, this user MUST set this restriction, but not significant. The suffix should not be specified for the application module;
- the implementation created by HelpersRegistrar can provide everything that I need for the future generation of the factory code: the name of the event class, the name of the helper class, the package (these are two common packages for visibility of packages between the helper and the event) - all the lines included in the POJO;
in the application module. I generate helpers - as usual, I get HelperRegistrars with my package, create an instance, run their contents to enrich my factory with code that provides helpers from other modules. All I need for this is the class names and the package.
Voila! My factory can provide instances of helpers both from the application module and from other modules.
The only uncertainty is the procedure for creating and running instances of the processor class in the application module and in other modules. I did not find any solid information about this, but my example shows that the compiler (and therefore code generation) first starts in the module we depend on, and then in the application module (otherwise, compiling the application module will be f. .cked). This gives us reason to rely on a known order of code execution in different modules.
Another slightly similar approach is to skip the registrars, generate factories in all modules, and write factory in the application module to use other factories that you get and name the same way as the registrars above.
An example can be seen here: https://github.com/techery/janet-analytics - this is the library in which I applied this approach (the one who does not have registrars, since I have factories, but this may not be for you )
P. S .: the suffix param parameter can be switched to the simpler "-Amylibraryname.library = true", and the names of factories / registrars can be auto-generated / increased