我有兴趣为 maven-processor-plugin 编写一个注释处理器。我对 Maven 比较陌生。
处理器 Java 源代码应该位于项目路径中的哪个位置(例如:src/main/java/...),以便正确编译它,但最终不会成为我的工件 JAR 文件的一部分?
最简单的方法是将注释处理器保留在作为依赖项包含的单独项目中。
如果这不适合您,请使用此配置
编译器插件:
<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>
(请注意,这必须在两次编译运行之间执行,因此必须将此代码放在 pom.xml 中after上面的maven-compiler-plugin配置)
罐子插件:
<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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)