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

问题描述

这是我的Maven命令

Here is my Maven command

mvn clean compile test-compile test

此项目

但是我面对

[错误]没有更多的标记-无法解析错误消息:Groovy:无法解析类Delegate,无法找到用于注释的类[错误] 12. D:\ Projects \ lombok-groovy-example-master \ src \ main \ groovy \ prystasj \ lombok \ example \ groovy \ Rocket.groovy中的错误(第5行)[ERROR] @Data

[ERROR] no more tokens - could not parse error message: Groovy:unable to resolve class Delegate , unable to find class for annotation[ERROR] 12. ERROR in D:\Projects\lombok-groovy-example-master\src\main\groovy\prystasj\lombok\example\groovy\Rocket.groovy (at line 5)[ERROR] @Data

mvn --version

mvn --version

Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T22:39:06+03:00)

java -version

java -version

java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

存储库中的代码

<properties>
    <groovy.version>2.0.5</groovy.version>
    <java.version>1.6</java.version>
    <lombok.version>0.11.4</lombok.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
    <compilerId>groovy-eclipse-compiler</compilerId>
    <fork>true</fork>
    <verbose>false</verbose>
    <source>${java.version}</source>
    <target>${java.version}</target>
    <encoding>${project.build.sourceEncoding}</encoding>
    <compilerArguments>
    <javaAgentClass>lombok.core.Agent</javaAgentClass>
    </compilerArguments>
    </configuration>
    <dependencies>
    <dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-eclipse-compiler</artifactId>
    <version>2.7.0-01</version>
    </dependency>
    <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>${lombok.version}</version>
    </dependency>//...

类(git上的文件不同!)

Class (file on git differs!)

@Data
public class Rocket {
}

推荐答案

您不应该将Lombok用于Groovy,它只能用于Java.

You shouldn't use Lombok for Groovy, it is intended to be used only with Java.

Groovy具有内置注释@Canonical,它可以满足您的需求:

Groovy has built-in annotation @Canonical which does what you want:

  • 它创建有用的equals,hashCode和toString方法
  • 它创建无参数和元组构造函数

因此,在您的情况下使用:

So in your case use:

@Canonical
public class Rocket {}

此外,您无需在Groovy中为字段创建getter和setter.如果将任何字段添加到类中,Groovy会创建吸气剂和吸气剂.

Additionally you don't need to create getters and setters for fields in Groovy. If you add any field to your class, Groovy would create getters and setters.

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

08-01 23:32