为maven-processor-plugin编写注释处理器 [英] Writing an annotation processor for maven-processor-plugin
问题描述
我有兴趣为maven-processor-plugin编写注释处理器。我对Maven来说比较新。
I am interested in writing an annotation processor for the maven-processor-plugin. I am relatively new to Maven.
项目路径中的处理器Java源代码应该去哪里(例如:src / main / java / ...)以便它适当编译,但不会作为我的工件JAR文件的一部分结束?
Where in the project path should the processor Java source code go (e.g.: src/main/java/...) so that it gets compiled appropriately, but does not end up as part of my artifact JAR file?
推荐答案
最简单的方法是保留注释处理器在一个单独的项目中包含为依赖项。
The easiest way is to keep your annotation processor in a separate project that you include as dependency.
如果这对您不起作用,请使用此配置
If that doesn't work for you, use this config
编译器插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
<inherited>true</inherited>
<executions>
<execution>
<id>default-compile</id>
<inherited>true</inherited>
<configuration>
<!-- limit first compilation run to processor -->
<includes>path/to/processor</includes>
</configuration>
</execution>
<execution>
<id>after-processing</id>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
<inherited>false</inherited>
<configuration>
<excludes>path/to/processor</excludes>
</configuration>
</execution>
</executions>
</plugin>
处理器插件:
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>compile</phase>
<configuration>
<processors>
<processor>com.yourcompany.YourProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
(请注意,这必须在两次编译运行之间执行,因此必须放置此项上面的maven-compiler-plugin配置之后的pom.xml 中的代码)
(Note that this must be executed between the two compile runs, so it is essential that you place this code in the pom.xml after the above maven-compiler-plugin configuration)
Jar插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<excludes>path/to/processor</excludes>
</configuration>
<inherited>true</inherited>
</plugin>
这篇关于为maven-processor-plugin编写注释处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!