5

I have a project composed of several BUCK modules. Each module uses the same annotation processor to generate a single file for each annotated class. For the sake of simplicity, for each annotated class:

package com.myproject.module1;

@Marker
public class SomeFoo {
  // ... code ...
}

a single class will be generated in the same package:

package com.myproject.module1;

@Generated
public class SomeFoo$$Marker {
  // ... generated code ...
}

Let's say I have two such modules: module1 and module2

Lastly, I have a module3 which is dependent on both above-mentioned modules.

This module contains another annotation:

package com.myproject.module3;

@MarkerCollector
public class Bar {
}

I'm trying to use the same annotation processor (could be a separate one as well), to generate a class that references all previously generated files (due to classes marked with @Marker.

The problem is that the annotation processor runs for each module separately, when run in module3, the annotation processor doesn't 'see' the files generated in other modules.

I've tried using the annotation processor's Filer to create a resource file and write the class names of all generated files, but this resource file is too, created per module.

What's the best way to aggregate/access generated code from different modules?

Lior
  • 7,845
  • 2
  • 34
  • 34
  • Did you ever find a solution? I'm currently looking for a similar answer in relation to an Android project with multiple modules. I've considered allowing the annotation processor to generate each file and then have a Gradle task to copy over into the top tier module all of those files which are then annotated to allow that top tier module to process them into a unified class. – fakataha Jul 21 '16 at 23:22

1 Answers1

0

If you are working with gradle you can create a JavaCompile task and configure it as I did here. My project was targeting android so you will see variant just make sure you put your classPath there instead

AouledIssa
  • 2,528
  • 2
  • 22
  • 39