Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilation error - Groovy and Lombok

Here is my Maven command

mvn clean compile test-compile test

for this project

but I am facing with

[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

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

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)

Code from repository

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

Class (file on git differs!)

@Data
public class Rocket {
}
like image 984
Arthur Kharkivskiy Avatar asked Sep 16 '17 18:09

Arthur Kharkivskiy


People also ask

How to install the Lombok plugin?

We need to go to the Preferences | Plugins, open the Marketplace tab, type “lombok” and choose Lombok Plugin by Michail Plushnikov: Next, click the Install button on the plugin page:

How to fix compiler error in IntelliJ Lombok?

Install the IntelliJ Lombok plugin by searching for “Lombok” in Preferences -> Plugins and hitting install on the first hit. The compiler error should disappear after restarting IntelliJ.

What is the @builder annotation in project Lombok?

Learn how the @Builder annotation in Project Lombok can help you reduce boilerplate code when implementing the builder pattern to create instances of your Java classes. A comprehensive and very practical introduction to many useful usecases of Project Lombok on standard Java code.

What is Lombok in Eclipse?

Overview Lombok is a library that facilitates many tedious tasks and reduces Java source code verbosity. Of course, we usually want to be able to use the library in an IDE, which requires additional setup. In this tutorial, we'll talk about configuring Lombok in two of the most popular Java IDEs — IntelliJ IDEA and Eclipse.


1 Answers

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

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

  • it creates useful equals, hashCode and toString methods
  • it creates no-arg and tuple constructor

So in your case use:

@Canonical
public class Rocket {}

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.

like image 148
Krzysztof Atłasik Avatar answered Nov 01 '22 00:11

Krzysztof Atłasik