Maven Groovy 和 Java + Lombok [英] Maven Groovy and Java + Lombok
问题描述
我正在尝试将 groovy 添加到利用 Lombok 的现有 Java Maven 项目中.不幸的是,当我使用下面的 pom 片段启用 groovy-maven-eclipse 编译器时,我的 lombok 注释的 java 文件无法编译.据我所知,Lombok 根本不参与 java 文件的编译.
I am trying to add groovy to an existing Java Maven project that leverages Lombok. Unfortunately when I enable the groovy-maven-eclipse compiler with the pom fragment below, my lombok annotated java files fail to compile. As far as I can tell, Lombok is not participating in the compilation of java files at all.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.6.0-01-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
我还应该指出,在 eclipse(使用 m2e)中时一切正常.当我尝试做一个 mvn 包时,我的问题出现了.
I should also point out that while in eclipse (with m2e) everything works fine. My problem arises when I try to do a mvn package.
推荐答案
@Todd:如果您不需要使用一些 groovy 工具开发 maven 插件,groovy-eclipse-compiler 是最佳选择(请参阅 http://groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven).
@Todd: The groovy-eclipse-compiler is the best choice if you don't need to developp maven plugin with some groovy tooling (see http://groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven).
@Ambience:您在 http://jira.codehaus.org/browse 找到了相关问题/GRECLIPSE-1293.此错误现已通过最新的 groovy-eclipse-compiler 2.6.1-01-SNAPSHOT 修复.
@Ambience: you reached the issue related at http://jira.codehaus.org/browse/GRECLIPSE-1293. This bug is now fixed with latest groovy-eclipse-compiler 2.6.1-01-SNAPSHOT.
注意:现在可用的最新版本是 2.9.1-01,请参阅 http://docs.groovy-lang.org/latest/html/documentation/tools-groovyeclipse.html
Note: The latest version available is now 2.9.1-01, see http://docs.groovy-lang.org/latest/html/documentation/tools-groovyeclipse.html
你必须像这样修改你的pom:
You have to modify your pom like this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
<fork>true</fork>
<compilerArguments>
<javaAgentClass>lombok.launch.Agent</javaAgentClass>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.1-01</version>
</dependency>
<!-- for 2.8.0-01 and later you must have an explicit dependency on groovy-eclipse-batch -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.3.7-01</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.4</version>
</dependency>
</dependencies>
</plugin>
必填部分:
<fork>true</fork>
<compilerArguments>
<javaAgentClass>lombok.launch.Agent</javaAgentClass>
</compilerArguments>
在 maven-compiler-plugin 中添加对 lombok 的依赖
The added dependency on lombok inside the maven-compiler-plugin
更新版本
这篇关于Maven Groovy 和 Java + Lombok的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!