When I try to compile my project using groovy-eclipse compiler with following classes:
import groovy.transform.builder.Builder
// @author: m on 10.05.16 22:15.
@Builder
class F {
int a
}
and
public class B {
int a;
public static void main(String[] args) {
F.FBuilder builder = F.builder();
F build = builder.a(1).build();
}
}
The following error occurs:
[INFO] Using Groovy-Eclipse compiler to compile both Java and Groovy files
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/m/git_repo/mix/src/main/java/B.java:[7,1] 1. ERROR in /Users/m/git_repo/mix/src/main/java/B.java (at line 7)
F.FBuilder builder = F.builder();
^^^^^^^^^^
F.FBuilder cannot be resolved to a type
[ERROR] /Users/m/git_repo/mix/src/main/java/B.java:[7,24] 2. ERROR in /Users/m/git_repo/mix/src/main/java/B.java (at line 7)
F.FBuilder builder = F.builder();
^^^^^^^
The method builder() is undefined for the type F
[ERROR] Found 2 errors and 0 warnings.
How to fix it? Please help
You may just want to use the
defkeyword in place ofF.FBuilder. When using joint compilation (java and groovy mixed in the same source folder), the groovy files are mapped into the Java model of Eclipse/JDT. However this mapping happens before many AST transformations have been applied, so additional types and methods like@Builderadds are not seen by Java.