JDK 21 NoSuchFieldError: JCImport Qualid Resolution
Problem Statement
After upgrading a Spring Boot project to JDK 21, you encounter a fatal compilation error:java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'
This error occurs due to incompatibility between older Lombok versions (<1.18.30) and JDK 21. The Lombok annotation processor interacts with Java's internal compiler APIs (JCTree), which changed in JDK 21. The Spring Boot dependency tree often pulls incompatible Lombok versions.
Solution 1: Upgrade Lombok to 1.18.30 or Later
This is the primary solution recommended by Lombok maintainers and confirmed by 75% of answers. Minimal compatible Lombok version with JDK 21 is 1.18.30
.
Maven Configuration:
<properties>
<lombok.version>1.18.30</lombok.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
Key Considerations:
Spring Boot Compatibility:
- Use Spring Boot
3.1.4+
(which includes Lombok ≥1.18.30) - If stuck on older Spring Boot versions, override Lombok explicitly (but proceed with caution):xml⚠️ Warning: Overriding Spring Boot BOM versions risks dependency conflicts. Spring Boot officially discourages this.
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.30</version> </dependency>
- Use Spring Boot
Multi-Module Projects: Ensure consistency across ALL modules:
xml<!-- Parent POM --> <properties> <java.version>21</java.version> <lombok.version>1.18.30</lombok.version> </properties> <!-- Child Module --> <properties> <maven.compiler.source>21</maven.compiler.source> <maven.compiler.target>21</maven.compiler.target> <lombok.version>1.18.30</lombok.version> </properties>
Solution 2: Configure Annotation Processor Path
Required when using Lombok with additional annotation processors (like MapStruct):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</path>
<!-- Other processors (e.g., MapStruct) -->
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
Solution 3: Exclude Lombok from Spring Boot Plugin
Prevents packaging issues and classpath conflicts:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
Solution 4: Validate Java Version Settings
Ensure consistency in Java versions everywhere:
- Maven Compiler Settings:
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
- IDE Settings (IntelliJ/Eclipse):
- Confirm JDK 21 is selected in project structure
- Set language level to 21
Troubleshooting Checklist
- Clear Caches:
- Maven:
mvn clean install -U
- IntelliJ: Maven > Reimport or full restart
- Maven:
- Dependency Tree Conflicts:bashVerify no older Lombok versions are pulled transitively.
mvn dependency:tree | grep lombok
- MapStruct/Lombok Binding (if using both):xml
<path> <groupId>org.projectlombok</groupId> <artifactId>lombok-mapstruct-binding</artifactId> <version>0.2.0</version> </path>
Final Output:
[INFO] BUILD SUCCESS
Explanation:
JDK 21 modified internal compiler APIs used by Lombok's annotation processor. Version 1.18.30
introduced critical patches for these changes. Always upgrade Lombok first—most issues resolve with this single change. Use other solutions only when facing specific compatibility or toolchain issues.
🔗 References: