Honza Zidek
Honza Zidek

Reputation: 20316

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?

Upvotes: 363

Views: 406178

Answers (13)

Ajinkya Gurav
Ajinkya Gurav

Reputation: 19

Changing the lombok version to 1.18.30 resolved my issue. I'm using JDK 17 in my application.

Upvotes: 0

Honza Zidek
Honza Zidek

Reputation: 20316

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.

Upvotes: 588

Yuvaraj G
Yuvaraj G

Reputation: 1237

I observed this issue. I use lombok 1.18.30. In my case, in one of my nested project, the maven settings for java compiler version was still pointing to 17 instead of 21. Correcting it fixed the issue.

Upvotes: 1

Mounir bkr
Mounir bkr

Reputation: 1665

I just increased springframework version to 3.2.3 and it works:

 <modelVersion>4.0.0</modelVersion>
 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    ***<version>3.2.3</version>***
    <relativePath/> <!-- lookup parent from repository -->
 </parent>

Or you try to increase lombok version to the last one in your pom.xml

<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.32</version>
        <scope>provided</scope>
    </dependency>

the two solutions work for me

Upvotes: 7

Salah dine Maham
Salah dine Maham

Reputation: 343

The problem is your JDK version of your Editor and that of your project. Check your Pom.xml file and change to the appropriate version. For me, it's jdk17.

Upvotes: -1

MartinF
MartinF

Reputation: 191

I also had today this problem after changing from Java 19 -> 21.

I also upgraded Spring boot version from 3.0.4 -> 3.2.3

I followed recommended approach to only increase lombok version to 1.18.30. Then error disapeared but I had issues with beans and dependencies so I returned spring boot version back to 3.0.4 and all works fine with java 21 and lombok.

I also tried to test which version of spring boot is making problem so I went from 3.0.4 to 3.2.2 and 3.1.8 is fine but from 3.2.2 is making problems with dependencies. I am using webflux from project reactor, so I will now stick with 3.1.8.

So there is also probably some change in last spring boot release that causes compatible issues with lombok I guess. I followed this article https://1kevinson.com/nosuchfielderror-jcimport-does-not-have-member-field-jctree-qualid/ below I cut how I have it in my pom.xml, I use Maven.

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.4</version>
        <relativePath/> <!-- lookup parent from repository -->
 </parent>
.....
<properties>
        <java.version>21</java.version>
</properties>
.....
<dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
            <version>1.18.30</version>
            <scope>provided</scope>
</dependency>
...

<plugin>
              <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.project-lombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>

Upvotes: 10

AMIT PRAJAPATI
AMIT PRAJAPATI

Reputation: 1

Actually, even I've been getting the same error but for me, all I need to do was to change the Java JDK version and the Language level in the Project Structure (I had the following configuration in my project :-

  • Spring boot version 2.7.0
  • Lombok version is 1.18.24
  • Java 11

Project Structure

Upvotes: -4

stackinfostack
stackinfostack

Reputation: 726

I was facing same issue. And i had also make it 1.18.30. But still it was not working. In that i was making mistake in annotationProcessorPaths. In that i had also dependency of projectlombok but version given 1.18.28 and it was not working. So final change below working fine.

  • Spring boot 3.2.2

  • Java 21

  • projectlombok 1.18.30

  • <org.projectlombok.version>1.18.30</org.projectlombok.version>

     <annotationProcessorPaths>
                 <path>
                     <groupId>org.mapstruct</groupId>
                     <artifactId>mapstruct-processor</artifactId>
                     <version>${org.mapstruct.version}</version>
                 </path>
                 <path>
                     <groupId>org.projectlombok</groupId>
                     <artifactId>lombok</artifactId>
                     <version>${org.projectlombok.version}</version>
                 </path>
                 <path>
                     <groupId>org.projectlombok</groupId>
                     <artifactId>lombok-mapstruct-binding</artifactId>
                     <version>${lombok-mapstruct-binding.version}</version>
                 </path>
             </annotationProcessorPaths>
    

Upvotes: 3

Daniel Kaplan
Daniel Kaplan

Reputation: 67474

When I received this error, my pom.xml looked like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <!-- ... -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- ... -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <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>
        </plugins>
    </build>

</project>

I modified it to look like this, and the error went away:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <!-- ... -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- ... -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <!-- <optional/> Removed -->
            <version>1.18.30</version> <!-- Added -->
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <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>
        </plugins>
    </build>

</project>

I found the answer in this GitHub comment, and you can find more background information there, too. Another user states this is a workaround, not a solution, but I haven't dug into it deep enough to form my own opinion.


I'm throwing my own answer into the ring because I feel it's more comprehensive than the others: It shows more of the pom.xml. Others include an excerpt of the pom.xml and assume the rest of it looks a specific way.

For example, one answer tells you to add a version number to lombok without telling you to exclude it from spring-boot-maven-plugin. Another answer has the opposite problem.

Upvotes: 13

Monish Chhadwa
Monish Chhadwa

Reputation: 199

Note that if you still get the error after updating to 1.18.30 in IntelliJ even after you rerun the build, its because IntelliJ has some cache which is still picking up the previous lombok version. Try one of these in that case:

  1. Right click the pom.xml file and select Maven > Reimport or Maven > Reload (for newer versions of IntelliJ)
  2. Restart IntelliJ (noob, but the best solution usually)

Upvotes: 2

Lucas M. R&#237;os
Lucas M. R&#237;os

Reputation: 5

This work for me

Replace this:

...
<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <version>1.18.XX</version>
  <scope>provided</scope>
</dependency>
...

With this:

...
<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <version>1.18.30</version>
  <scope>provided</scope>
</dependency>
...

Upvotes: -2

user1419261
user1419261

Reputation: 944

Use the Lombok exclude in the Spring Boot Maven plugin and it should work for JDK 21.

    <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>

</plugins>

Upvotes: 4

Arundev
Arundev

Reputation: 1944

I followed the first answer from here and I made the following changes. Previously, it brought the Lombok version 1.18.20 as default, and I needed to feed the latest which resolved the issue for me when I moved from Spring Boot 2.XX to 3.3.3.

When doing a mvn dependency:tree, you can see from where the lower version is coming from and if you want exclude that and new or just add new and check one more time. Still it's pulling the older version. If not, just add a new one like below. So far there isn't any issue with this solution.

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.30</version>
    <scope>provided</scope>
</dependency>

Upvotes: 44

Related Questions