使用 maven-compiler-plugin 处理 Maven 注释 [英] Maven annotation processing with maven-compiler-plugin
问题描述
我尝试编译包含生成源代码的注释的代码.我使用 maven-compiler-plugin
和 build-helper-maven-plugin
.我的 POM 看起来像这样:
I try to compile my code that contains annotations that generate source code. I use the maven-compiler-plugin
and build-helper-maven-plugin
. My POM is looking like that:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<generatedSourcesDirectory>${project.build.directory}/generated-sources/apt</generatedSourcesDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/apt</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
当我运行mvn compile
时,将${project.build.directory}/generated-sources/apt
添加为源目录,并生成生成的源在正确的目录中.但是由于缺少对生成的类的引用,我得到了编译器错误.就好像生成的源目录没有包含在编译过程中.
When I run mvn compile
, ${project.build.directory}/generated-sources/apt
is added as a source directory, and the generated sources are generated in the correct directory. But I get compiler errors because of missing references to the generated classes. It's like the generated source directory is not included in the compilation process.
我也尝试了 apt-maven-plugin
它不会产生任何东西.和 maven-annotation-plugin
但它的行为如上所述.
I also try apt-maven-plugin
which does not generate anything. And maven-annotation-plugin
but it behaves as describe above.
推荐答案
能不能试试最新版的 maven 编译器插件(2.3.2
)?
Can you try with the latest version of maven compiler plugin (2.3.2
)?
此外 build-helper-maven-plugin
不是必需的,因为看起来您正在使用 maven-compiler-plugin
本身从注释生成源代码.
Also build-helper-maven-plugin
is not required since it looks like you are using the maven-compiler-plugin
itself to generate the sources from the annotation.
这篇关于使用 maven-compiler-plugin 处理 Maven 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!