早几天使用maven-processor-plugin插件做一个很简单的APT例子的时候出现异常
error:annotation processor xx not found
错误:找不到注解处理程序xx
但是processor是存在的!当时没找到原因。
今天突然想到在maven 调用maven-processor-plugin是在<phase>generate-sources</phase>的时候,而我又习惯同时运行mvn clean install,所以这个时候processor还没有编译,于是就报找不到processor错误了!
解决方法很简单,只要让processor先编译了。要不把processor放到别的工程里以依赖包的形式加入,要不把maven-processor-plugin插件移到一个profile里,比如
<profiles> <profile> <id>apt</id> <build> <plugins> <plugin> <groupId>org.bsc.maven</groupId> <artifactId>maven-processor-plugin</artifactId> <executions> <execution> <id>process</id> <goals> <goal>process</goal> </goals> <phase>generate-sources</phase> <configuration> <outputDirectory>target/generated-sources/java</outputDirectory> <processors> <processor>org.adaikiss.xun.apt.XunProcessor</processor> </processors> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
然后先运行mvn clean install,再运行mvn eclipse:clean eclipse:eclipse -Papt或mvn install -Papt