简体   繁体   English

来自不同降压模块的注释处理器的汇总输出

[英]Aggregate output from Annotation Processors of different buck modules

I have a project composed of several BUCK modules.我有一个由几个 BUCK 模块组成的项目。 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假设我有两个这样的模块: module1module2

Lastly, I have a module3 which is dependent on both above-mentioned modules.最后,我有一个依赖于上述两个模块的module3

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 .我正在尝试使用相同的注释处理器(也可以是一个单独的注释处理器)来生成一个引用所有先前生成的文件的类(由于用@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 .问题是注释处理器分别为每个模块运行,当在模块 3 中运行时,注释处理器不会“看到”在其他模块中生成的文件

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 .我已经尝试使用注解处理器的Filer创建一个资源文件并写入所有生成文件的类名,但是这个资源文件也是每个模块创建的。

What's the best way to aggregate/access generated code from different modules?聚合/访问来自不同模块的生成代码的最佳方法是什么?

If you are working with gradle you can create a JavaCompile task and configure it as I did here .如果您正在使用 gradle,您可以创建一个JavaCompile任务并像我在这里所做的那样对其进行配置。 My project was targeting android so you will see variant just make sure you put your classPath there instead 🤓我的项目是针对 android 的,所以你会看到variant只要确保你把你的 classPath 放在那里 🤓

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM