2011-02-09 113 views
3

我尝试编译包含生成源代码的注释的代码。我使用maven-compiler-pluginbuild-helper-maven-plugin。我的POM正在寻找这样的:使用maven-compiler-plugin进行Maven注解处理

 <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添加为源目录,生成的源在正确的目录中生成。但是由于缺少对生成的类的引用,导致编译器错误。这就像生成的源目录不包含在编译过程中。

我也尝试apt-maven-plugin它不会产生任何东西。并且maven-annotation-plugin但它的行为如上所述。

回答

0

你可以试用最新版本的maven编译器插件(2.3.2)吗?

也不需要build-helper-maven-plugin,因为它看起来像你使用maven-compiler-plugin本身来从注释中生成源。

+0

我有同样的问题,它工作正常使用`2.3.2`,有一个“虚假的错误”关于'失踪symbol`定义,但它的只是在第一遍生成* Metamodel * – dcestari 2011-02-24 00:01:42

1

Maven的注解插件的版本2.0.7-SNAPSHOT应该解决的问题