spring-bootcompiler-errorsupgradelombokjava-21

Compilation error after upgrading to JDK 21 - "NoSuchFieldError: JCImport does not have member field JCTree qualid"


After upgrading to JDK 21, I have the following compilation error in my Spring Boot project:

Fatal error compiling: java.lang.NoSuchFieldError:
Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'

Question:

What shall I do to use Java 21+ and still have the application compilable and runnable?


Solution

  • The culprit is Lombok. The minimal Lombok version compatible with JDK 21 is 1.18.30.

    This implies that the minimal Spring Boot version is 3.1.4, unless you want to meddle with the Spring Boot dependency management and set the Lombok version in your project differently from the Spring Boot BOM defined in spring-boot-dependencies.

    See: [BUG] Lombok 1.8.26 incompatible with JDK 21 #3393

    Although certainly it is possible to set the your own Lombok version, differently than in the Spring Boot BOM, the Spring Boot documentation on Customize Dependency Versions itself warns against it:

    WARNING: Each Spring Boot release is designed and tested against this specific set of third-party dependencies. Overriding versions may cause compatibility issues.