Spring lombok error _ compiler does not export com.sun.tools.javac.processing to unnamed module



1. Problem

When i program spring framework, i can see like this error.

plugins {
    id 'org.springframework.boot' version '2.4.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

    runtimeOnly 'com.h2database:h2'

    annotationProcessor("org.projectlombok:lombok")
    compileOnly("org.projectlombok:lombok")
}

test {
    useJUnitPlatform()
}
Cause: class lombok.javac.apt.LombokProcessor (in unnamed module @0x45438a81) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x45438a81

image lombok problem

2. Solution

This error arise because of Jdk16 version and lombok version problem. When we use Jdk11, we can use lombok like problem gradle source. But when we use Jdk16, we can use lombok only we write version.

plugins {
    id 'org.springframework.boot' version '2.4.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

    runtimeOnly 'com.h2database:h2'

    annotationProcessor("org.projectlombok:lombok:1.18.20")
    compileOnly("org.projectlombok:lombok:1.18.20")
}

test {
    useJUnitPlatform()
}

When we change "org.projectlombok:lombok" -> "org.projectlombok:lombok:1.18.20", we can solve the problem.

image lombok problem solve