在Maven中为注释处理器设置生成的源目录

Rob*_*anu 6 java maven-2 maven annotation-processing

我正在尝试将使用注释处理器生成源的构建移动到Maven.我尝试过如下配置maven-compiler-plugin:

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <fork>true</fork>
                <compilerArgument>-s ${project.build.directory}/target/generated-sources/annotation-processing</compilerArgument>
            </configuration>
        </plugin>
    </plugins>
Run Code Online (Sandbox Code Playgroud)

但是javac失败了

[INFO] Compilation failure  
Failure executing javac,  but could not parse the error:
javac: invalid flag: -s /home/robert/workspaces/betbrain/sportsengine.common/sportsengine.bean.test/target/target/generated-sources/annotation-processing  
Usage: javac <options> <source files>  
use -help for a list of possible options
Run Code Online (Sandbox Code Playgroud)

据我所知,-s应该在源文件之前传递给javac,但maven之后传递它.

如何将-s标志正确传递给maven-compiler-plugin?


更新:maven-annotation-plugin似乎不起作用.

配置为时

        <plugin>
            <groupId>org.bsc.maven</groupId>
            <artifactId>maven-processor-plugin</artifactId>
            <version>1.0-SNAPSHOT</version>
            <executions>
                <execution>
                    <id>process</id>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <phase>generate-sources</phase>
                    <configuration>
                        <outputDirectory>${generated.sources.directory}</outputDirectory>
                        <processors>
                            <processor>xxx.annotation.EnforceJavaBeansConventionsProcessor</processor>
                        </processors>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

执行失败

[INFO] [processor:process {execution: process}]
error: Annotation processor 'xxx.annotation.EnforceJavaBeansConventionsProcessor' not found
1 error
Run Code Online (Sandbox Code Playgroud)

Pas*_*ent 5

我可能会遗漏一些东西,但你不应该:

  1. target/generated-sources/annotation-processing在此阶段生成源generate-sources?apt -maven-pluginmaven-annotation-plugin可以提供帮助。

  2. 将源编译为在maven-compiler-pluginmaven-build-helper-plugintarget/classes中使用时包含生成的源吗?<includes>

编辑:位于哪里xxx.annotation.EnforceJavaBeansConventionsProcessor?您不需要添加到“使用”dependencies页面上记录的 maven-annotation-plugin 的配置吗?

<plugin>
  <groupId>org.bsc.maven</groupId>
  <artifactId>maven-processor-plugin</artifactId>
  <version>1.0-SNAPSHOT</version>
  <executions>
    <execution>
      <id>process</id>
      <goals>
        <goal>process</goal>
      </goals>
      <phase>generate-sources</phase>
      <configuration>
        <outputDirectory>src/main/generated</outputDirectory><!-- PROCESSOR OUT DIR --> 
        <processors><!-- LIST OF PROCESSOR CLASS(S) -->
          <processor>org.bsc.apt.BeanInfoAnnotationProcessor</processor>
        </processors>
      </configuration> 
    </execution>
  </executions>
  <dependencies/><!-- ADD DEPENDENCIES HERE IF REQUIRED -->
</plugin>
Run Code Online (Sandbox Code Playgroud)

PS:我不会使用src/main/generated作​​为输出目录,而是使用target/generated-sources.


Rob*_*anu 5

该插件使用了编码的Windows类路径分隔符来构建类路径,因此它在我的Linux机器上失败了.

提交的补丁:


Jes*_*ick 5

不完全是你的问题的答案,但感兴趣:

http://jira.codehaus.org/browse/MCOMPILER-75

我担心在Maven中使用JSR 269存在许多问题,至少使用默认的编译器插件.