Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anyone used Ant4Eclipse with Project Lombok?

Has anyone successfully used Ant4Eclipse (http://www.ant4eclipse.org/) in combination with Project Lombok (http://projectlombok.org/)?

Lombok provides annotations for removing boilerplate code; however, it doesn't appear to play nicely with Ant4Eclipse (headless compilation of Eclipse projects). For instance, the following Lombok sample compiles fine in Eclipse and javac:

import lombok.Getter;
public class LombokTest {
  private @Getter String foo; 
  public LombokTest() {
    String s = this.getFoo();
  }
}

But compiling with Ant4Eclipse's <buildJdtProject> yields the following:

[javac] Compiling 1 source file
[javac] ----------
[javac] 1. WARNING in C:\dev\Java\workspace\LombokTest\src\LombokTest.java (at line 4)
[javac]     private @Getter String foo;
[javac]                            ^^^
[javac] The field LombokTest.foo is never read locally
[javac] ----------
[javac] 2. ERROR in C:\dev\Java\workspace\LombokTest\src\LombokTest.java (at line 8)
[javac]             String s = this.getFoo();
[javac]                             ^^^^^^
[javac] The method getFoo() is undefined for the type LombokTest
[javac] ----------

Has anyone successfully used these libraries together?

Thanks!

Edit: sample project demonstrating the issue

like image 515
gmcnaughton Avatar asked Apr 05 '10 05:04

gmcnaughton


2 Answers

I eventually managed to compile a lombok project with ant4eclipse by delomboking the project first with

<delombok verbose="true"; encoding="UTF-8" 
    to="${workspaceDirectory}/myproject/src" 
    from="${workspaceDirectory}/myproject/src-original" />
like image 90
Krzysztof Dziadek Avatar answered Sep 18 '22 05:09

Krzysztof Dziadek


IIRC in order to use Lombok in Eclipse, there's a parameter required at start-up to introduce Lombok's Java Agent into the JDT compile process. This is normally specified in the eclipse.ini file. If Ant4Eclipse does not also make use of those parameters (I don't see why it would) you may have to specify the -javaagent:lombok.jar parameter for that too.

DISCLAIMER: this is only a guess.

like image 41
Grundlefleck Avatar answered Sep 20 '22 05:09

Grundlefleck