有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java自定义注释处理器。进程()未被调用

我正在尝试创建一个自定义注释处理器,但它没有被调用。这是一个很好的例子。虽然如此,但它似乎从未调用。过程任何帮助都将不胜感激

版本:

  • 科特林(1.3.72)
  • JRE(11.0.7)
  • 马文(3.8.0)

这是我从控制台的输出:

[INFO] --- maven-compiler-plugin:3.8.0:compile (java-compile) @ mesh ---
[INFO] Changes detected - recompiling the module!
Processor is being init!!
Processor is done init!!

注释:

package my.path.annotations

@Target(AnnotationTarget.CLASS)
annotation class MyAnnotation()

注释处理器:

package my.path.annotations

import <...>

@SupportedAnnotationTypes("my.path.annotations.MyAnnotation")
class MyAnnotationProcessor : AbstractProcessor() {
    private var elementUtils: Elements? = null
    private var messager: Messager? = null

    @Synchronized
    override fun init(env: ProcessingEnvironment?) {
        println("Processor is being init!!")
        super.init(env);
        elementUtils = env!!.elementUtils;
        messager = env.messager;
        println("Processor is done init!!")
    }

    override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
        println("Processor is being run!!!")
        return true
    }

    override fun getSupportedSourceVersion(): SourceVersion? = SourceVersion.latestSupported()
}

来自pom的片段。xml

                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <annotationProcessors>
                        <annotationProcessor> my.path.annotations.MyAnnotationProcessor</annotationProcessor>
                    </annotationProcessors>
                </configuration>

META-INF/services/javax。注释。处理。处理器文件:

my.path.annotations.MyAnnotationProcessor

在类上使用:

@MyAnnotation
class SomeClass @Inject constructor(private val objectMapper: ObjectMapper) {

共 (0) 个答案