本文介绍了Maven Groovy和Java + Lombok的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Groovy添加到利用Lombok的现有Java Maven项目中。不幸的是,当我使用下面的pom片段启用groovy-maven-eclipse编译器时,我的lombok注释的java文件无法编译。据我所知,Lombok根本没有参与编译java文件。

 < plugin> 
< artifactId> maven-compiler-plugin< / artifactId>
< version> 2.3.1< / version>
<配置>
< compilerId> groovy-eclipse-compiler< / compilerId>
<详细>真< /详细>
< / configuration>
<依赖关系>
< dependency>
< groupId> org.codehaus.groovy< / groupId>
< artifactId> groovy-eclipse-compiler< / artifactId>
< version> 2.6.0-01-SNAPSHOT< / version>
< /依赖关系>
< /依赖关系>
< / plugin>

我也应该指出,在eclipse中(使用m2e)一切正常。当我尝试做一个mvn包时,我的问题就出现了。解决方案

@Todd:groovy-eclipse编译器是最好的选择如果你不需要用一些常规工具开发maven插件(参见)。



@Ambience:您达成了相关问题。
现在这个bug已经被最新的groovy-eclipse-compiler 2.6.1-01-SNAPSHOT所修复。

注意:最新现在可用的版本为 2.9.1-01 ,请参阅



您必须修改您的pom是这样的:

 < plugin> 
< artifactId> maven-compiler-plugin< / artifactId>
< version> 3.1< / version>
<配置>
< compilerId> groovy-eclipse-compiler< / compilerId>
<详细>真< /详细>
< fork> true< / fork>
< compilerArguments>
< javaAgentClass> lombok.launch.Agent< / javaAgentClass>
< / compilerArguments>
< / configuration>
<依赖关系>
< dependency>
< groupId> org.codehaus.groovy< / groupId>
< artifactId> groovy-eclipse-compiler< / artifactId>
< version> 2.9.1-01< / version>
< /依赖关系>
gtg显式依赖。
< dependency>
< groupId> org.codehaus.groovy< / groupId>
< artifactId> groovy-eclipse-batch< / artifactId>
< version> 2.3.7-01< / version>
< /依赖关系>
< dependency>
< groupId> org.projectlombok< / groupId>
< artifactId> lombok< / artifactId>
< version> 1.16.4< / version>
< /依赖关系>
< /依赖关系>
< / plugin>

强制性部分:

 <叉>真< /叉> 

< compilerArguments>
< javaAgentClass> lombok.launch.Agent< / javaAgentClass>
< / compilerArguments>

在maven-compiler-plugin中增加了对lombok的依赖性

编辑:更新版本


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>

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: 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: 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.

Note: The latest version available is now 2.9.1-01, see http://docs.groovy-lang.org/latest/html/documentation/tools-groovyeclipse.html

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>

The mandatory parts:

<fork>true</fork>

<compilerArguments>
    <javaAgentClass>lombok.launch.Agent</javaAgentClass>
</compilerArguments>

The added dependency on lombok inside the maven-compiler-plugin

Edit: update versions

这篇关于Maven Groovy和Java + Lombok的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:31