How can we provide an annotation processor with a Java 11 module?
To register the annotation provider we need the following module-info entry:
import javax.annotation.processing.Processor;
import com.mycompany.mylib.impl.MyAnnotationProcessor;
module com.mycompany.mylib {
provides Processor with MyAnnotationProcessor;
}
Now, unfortunately, this is not enough since the packages javax.annotation.processing
, javax.lang.model.*
and javax.tools
are not in the java.base
module but in the java.compiler
module.
With Java SE 8 everything was just available in the JRE, but with Java 11 we get the option to use only a subset. With jlink
we then can create smaller runtime images.
Now, of course, I could just add the following to the module-info:
requires java.compiler;
But this would cause java.compiler
to be part of the custom runtime image as well.
But annotation processing is something special: it is code run at compile time, not at runtime. Thus it should not be part of the runtime image. It should only be a compile-time requirement/ dependency.
Is there a way to solve this with the Java 11 module system?