Javac "cannot find symbol" errors frequently in Gradle build

26 views
Skip to first unread message

Sunil

unread,
Jun 23, 2024, 4:53:36 AM (6 days ago) Jun 23
to Project Lombok
Environment: 
JDK 17
Gradle 7.x (also tried 8.x)
Lombok gradle plugin 7.x (or 8.x) (also tried Lombok 1.18.30 directly)

When I try to compile my code using ./gradlew clean compileJava, the build fails randomly around 50% of the time. with javac errors like these on Lombok-annotated classes:

/Users/sunil/...XYZService.java:36: error: cannot find symbol
@RequiredArgsConstructor(onConstructor_ = { @Autowired })
                         ^
  symbol:   method onConstructor_()
  location: @interface RequiredArgsConstructor
/Users/sunil/...XYZService.java:36: error: cannot find symbol
    private void getCredit(Discovery.DiscoveryBuilder builder) {
                                              ^
  symbol:   class DiscoveryBuilder
  location: class Discovery

  • I have gone through all ~300 reported javac errors, I cannot find anything problematic in the code.
  • There is no pattern - if I run the exact build thing again and again, sometimes compile succeeds, sometimes it fails.
  • This very same code always compiles fine inside Eclipse IDE.
  • I am using only these common Lombok annotations: AllArgsConstructor, RequiredArgsConstructor, NoArgsConstructor, Builder, Builder.Default, Data, Getter, Setter, NonNull, ToString, Slf4j.
  • I have run Gradle with --debug and confirmed that Lombok is indeed in the processorpath and classpath of javac.
  • I have tried 2 different JDK 17s: Corretto and OpenJDK. No difference.
  • I tried Gradle with and without the Lombok plugin. No difference.
  • The problem happens on both MacOS and Amazon Linux.
I have been through any number of threads on SO and here, and I see people saying that there must be some class somewhere which has something Lombok doesn't "like". But how on earth do I find it?? I would appreciate any help, since this is driving me crazy now.

Many thanks,
Sunil



[This communication contains information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient/s. If you have received this communication in error, please delete the email and destroy any copies of it.]

Zoltán Csorba

unread,
Jun 24, 2024, 2:45:31 PM (5 days ago) Jun 24
to Project Lombok
For me, it seems that the 'onconstructor' attribute of the 'RequiredArgsConstructor' annotation is causing the problem. The documentation says (see [https://projectlombok.org/features/experimental/onX]), that this is an experimental feature and that different compiler versions may behave differently.
Is it an option for you to not use the 'onconstructor' in your code, or the generated constructors without the 'Autowired' annotation is not sufficient?
If it's just one class that needs this experimental feature, then it could be feasible to manually create those constructors to workaround this problem.

Sunil

unread,
Jun 25, 2024, 2:56:05 AM (5 days ago) Jun 25
to Project Lombok
We're using it all over the place. :( I ended up delombok-ing the whole repo.

Also I'm not sure that `onConstructor()` thing is the only reason; since it fails on the Builder references also...

Daniel López

unread,
Jun 25, 2024, 10:29:14 AM (4 days ago) Jun 25
to project...@googlegroups.com
Hi,
Not sure which version of Spring you are using, but, in case it helps, you no longer need to add the @Autowired annotation in the constructors. Just having the bean in the constructor is enough, so we removed all  @RequiredArgsConstructor(onConstructor_ = { @Autowired }) from our code. In any case, if you are having issues with other Lombok features, that won't help much.
Never seen those issues, but we use Maven so it might be a Graddle thing.
Good luck!
D.

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/project-lombok/01f7d87d-9158-4a9e-a4de-501b2bb718bcn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages