This seems to work for me:
import groovy.transform.builder.Builder
@Builder(builderClassName = "MyBuilder")
class NoMembers {
private int privateInt;
public int publicInt;
static int staticInt = 1;
}
class MyOtherClass {
public boolean containsValidFieldValues(List<Integer> expectedFieldValues) {
NoMembers.builder().build()
}
}
assert new MyOtherClass().containsValidFieldValues([])
The normal usage is all set up to avoid any problems with class resolution.
Cheers, Paul.
On Thu, Jun 5, 2025 at 2:59 AM Saravanan Palanichamy <[email protected]> wrote:
>
> Hello Users
>
> I am trying to use the builder annotation and am seeing compile errors. I am
> not sure if I am doing something wrong
>
>> package com.my.builder
>>
>> import groovy.transform.builder.Builder
>>
>> @Builder(builderClassName = "MyBuilder")
>> class NoMembers {
>> private int privateInt;
>> public int publicInt;
>> static int staticInt = 1;
>> }
>>
>> class MyOtherClass {
>> public boolean containsValidFieldValues(List<Integer>
>> expectedFieldValues) {
>> new NoMembers.MyBuilder().build()
>> }
>> }
>
>
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
> 14: unable to resolve class NoMembers.MyBuilder
> @ line 14, column 9.
> new NoMembers.MyBuilder().build()
> ^
>
> I am using this single line to compile
>>
>> GroovyClassLoader().parseClass(File("testdata/plugins/Builder.groovy"))
>
>
> It looks like the builder annotation is adding a new class and this happens
> after the resolver caused the compile error. Any help is appreciated.
>
> regards
> Saravanan