I have a Maven java project which includes a custom annotation processor:
@SupportedAnnotationTypes("com.example.Processor")
@SupportedSourceVersion(SourceVersion.RELEASE_17)
public class MyProcessor extends AbstractProcessor {
/*
code
*/
}
However, when I compile the project I get the error
"Annotation Processor com.example.MyProcessor not Found"
Here is my maven-compiler-plugin below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessors>
<annotationProcessor>
com.example.MyProcessor
</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
I have a file under META-INF/services called javax.annotation.processing.Processor which contains the custom annotation processor's name.
I looked over similar questions on this topic which suggest to disable annotation processing as the solution (i.e set proc:none under executions tag). However I don't want to disable annotation processing because I also want to use @Slf4j logging in the same project.
Any suggestions on how to get this to work?
I've faced with annotation processor problems, but with gradle. What has helped me:
Also baeldung baeldung says, that your own class should already be compiled, for instance, imported from another jar in the build dependencies. You can 1) set annotation processor in the copmiler settings or 2) add a specially structured jar with the processor class to the classpath of the compiler (you have to specify it in the META-INF/services/javax.annotation.processing.Processor file as a fully qualified class name of the processor).
One more variant - to generate the registration file automatically, you can use the @AutoService annotation from the Google's auto-service library with your own annotation processor.