我有兴趣为 maven-processor-plugin 编写注释处理器。我对 Maven 比较陌生。
处理器 Java 源代码应该在项目路径中的哪个位置(例如:src/main/java/...)以便正确编译,但最终不会成为我的工件 JAR 文件的一部分?
我有兴趣为 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>
(请注意,这必须在两次编译运行之间执行,因此必须将此代码放在上述 maven-compiler-plugin 配置之后的 pom.xml 中)
罐子插件:
<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>