开发者

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] ----------

Ha开发者_Python百科s anyone successfully used these libraries together?

Thanks!

Edit: sample project demonstrating the issue


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜