在Maven中为注释处理器设置生成的源目录 [英] Setting the generated source directory for annotation processors in Maven
本文介绍了在Maven中为注释处理器设置生成的源目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将使用注释处理器生成源的构建移动到Maven.我尝试过如下配置maven-compiler-plugin:
I'm trying to move a build which generates sources using an annotation processor to Maven. I've tried configuring the maven-compiler-plugin as follows:
<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>
但是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
据我所知,-s应该在源文件传递给javac之前传递,但maven在它传递之后.
As far as I can tell, -s should be passed before the source files to javac, but maven passes it after.
如何将-s
标志正确传递给maven-compiler-plugin?
How can I pass the -s
flag properly to the 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>
执行失败,并
[INFO] [processor:process {execution: process}]
error: Annotation processor 'xxx.annotation.EnforceJavaBeansConventionsProcessor' not found
1 error
推荐答案
该插件正在使用经过编码的Windows类路径分隔符来构建类路径,因此在我的Linux机器上失败了.
The plugin was using the harcoded Windows classpath separator to build the classpath, so it was failing on my Linux machine.
已提交的补丁程序:
- system dependent path separator character
- Allow the default processor discovery mechanism to run
这篇关于在Maven中为注释处理器设置生成的源目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文