I am writing a java annotation processor to collect metadata from the annotations in a body of code. I want the output file to start with the maven project version. Looking at the javac documentation for Oracle java 8, it appears I should be able to pass the project version as an option to the annotation processor using the notation -A key=value. So I configured the maven-compiler-plugin to set the core.versionId option to the project version as follows:
<configuration>
<compilerArgs>
<arg>-A core.versionId=${project.version}</arg>
</compilerArgs>
</configuration>
However, when I compile, I get the following error:
Fatal error compiling: key in annotation processor option '-A core.versionId=1.7.0-SNAPSHOT' is not a dot-separated sequence of identifiers
It seems that the project.version was correctly inserted, but the compiler failed to process the -A option as advertised. I must be missing something, but I cannot see what it is, and I can find no mention of this problem. Any help much appreciated.
Update: The error goes away if I remove the space, making the arg be
-Acore.versionId=${project.version},
but in this case the core.versionId option does not show up in the annotation processor.
It turns out that a critical piece of information was omitted from the original question. The module being compiled also needs weaving with AspectJ, which re-runs the compiler. The annotation processor was indeed running and producing its correct output during the compile step, but was being immediately overwritten by a second run of the annotation processor during the AspectJ weaving step. Adding a bit of configuration to the aspectj-maven-plugin clause solved the problem:
<configuration>
<proc>none</proc>
</configuration>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With