I have developed a custom annotation and custom annotation processor for Java Spring. However, when I include it in the project where I want to use it, it doesn’t work. It only works when I create the annotation processor in a separate project and include it as a module. How can I make it work in a single project?
My annotation class is
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface A {
}
My processor class is
@AutoService(Processor.class)
@SupportedSourceVersion(SourceVersion.RELEASE_11)
@SupportedAnnotationTypes("A")
public class AProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
{
processingEnv.getMessager().printMessage(
Diagnostic.Kind.ERROR,
"A annotation is used!");
return true;
}
}
My pom.xml file is
<groupId>org.example</groupId>
<artifactId>annotation-processing</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
However, never call
process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
method when the annotation processor is in same project.
It only works when I create the annotation processor in a separate project and include it as a module.