看来,我无法注册自己的注释处理器。但是使用 Google 的 AutoService 确实注册了我的注释处理器。它工作得非常出色。
因此,我确实将 javax.annotation.processing.Processor
文件放在resources/META-INF/services
了包含 AbstractProcessor 实现的包路径的目录下。而且我故意添加了错误消息,该错误消息必须使构建失败,如下所示。
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment?) : Boolean {
processingEnv.messager.printMessage(Diagnostic.Kind.ERROR, "Some Error !!")
// Some work
}
而且我确实仔细检查了我的行为,但我无法弄清楚首先出了什么问题。
所以真正的问题是为什么 Google 的 AutoService 确实有效而我的却没有?这一直困扰着我。