How to start annotation processing through maven 3.3?

For many years, we ran the maven-processor-plugin as a separate target (using proc:none in the maven-compiler-plugin). Finally, we are upgrading from maven 3.0.5 to the latest version 3.3.3, and I see that the maven-processor plugin basically looks dead. As far as I can tell, it has not been ported from Google code.

We use annotation processing primarily to create dagger classes. I can’t remember the reasons, but at that time (in dagger-1) we had the impression that it was better to do this in the generate-sources and generate-test-sources phases, and not during compile and test-compile , so for starters we used the maven-processor-plugin plugin. Please note that we want all this to play well in eclipse / m2e.

Is there a new, better way to start annotation processing from maven that works great for eclipse?

+3
java maven maven-3 dagger
source share
1 answer

You can use maven-compiler-plugin to handle annotations, as functionality exists in javac . To perform annotation processing and regular compilation in different phases, you can perform several executions of the plugin, one with annotation processing turned on, and the other with disabling. The configuration for this is as follows:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5</version> <executions> <execution> <id>process-annotations</id> <phase>generate-sources</phase> <goals> <goal>compile</goal> </goals> <configuration> <compilerArgs> <arg>-proc:only</arg> <arg>-processor</arg> <arg>MyAnnotationProcessor</arg> </compilerArgs> </configuration> </execution> <execution> <id>default-compile</id> <!-- using an id of default-compile will override the default execution --> <phase>compile</phase> <goals> <goal>compile</goal> </goals> <configuration> <compilerArgs> <arg>-proc:none</arg> </compilerArgs> </configuration> </execution> </executions> </plugin> 
+2
source share

All Articles