APT 使用
annotation-processor模块
JAVA APT 基于注解处 理器,本工程案例只是输出一些打印内容。
写一个processor
如果想了解更多注解处理器相关的知识,请阅读 Core-Java-Vol.-II-Advanced-Features-12th-Edition-Cay-S.-Horstmann.
如果在其它工程使用Processor jar包
- maven
- gradle
<!--...-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>com.whalefall</groupId>
<artifactId>annotation-processor</artifactId>
<version>0.0.1-SNAPSHOT</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
</path>
</annotationProcessorPaths>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<!--...Here are include lombok, thus I use the plugin.-->
dependencies {
// ...
annotationProcessor 'com.whalefall:annotation-processor:0.0.1-SNAPSHOT'
testAnnotationProcessor 'com.whalefall:annotation-processor:0.0.1-SNAPSHOT'
// if you are using processor in test code
// if you use this in other module of the aggregation project
annotationProcessor project(':annotation-processor')
}