views:

187

answers:

2

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

A: 

Supplied project does not compile out of the box with Eclipse JEE 3.5.2 using Java 6. The errors in Eclipse are the same as those given by ant4eclipse.

Thorbjørn Ravn Andersen
Sorry, I should have noted: you need to install Lombok into Eclipse first (by double-clicking lib/lombok/lombok.jar).
gmcnaughton
You mean add lombok.jar to build path?
Thorbjørn Ravn Andersen
No, lombok needs to hook into Eclipse. It uses a java agent to do that. If you download lombok.jar and run java -jar lombok.jar you'll get an installer screen, including a button that explains how it will modify your Eclipse installation. And yes, you also have to add it to the build path.
Roel Spilker
So the problem is that you need to hook lombok into your ant4eclipse configuration too. What does the lombok documentation say about using from within ant?
Thorbjørn Ravn Andersen
+1  A: 

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.

Grundlefleck