简体   繁体   中英

Lombok module not found with Java 11 and Gradle

Currently, I cannot get this project to run, somehow the Gradle cannot find the Lombok module. I'm using

  • lombok version 1.18.12
  • OpenJDK 11.0.8
  • Gradle 6.4

Based on this github issue , then the problem should be solved at this version, but it doesn't work for me.

Here is the error

> Task :Model-library:compileJava FAILED
/home/dauto98/path..to..project/src/main/java/module-info.java:2: error: module not found: lombok
    requires static lombok;

below is my gradle.build.kts file

plugins {
    java
    `java-library`
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation("junit", "junit", "4.12")

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

    testCompileOnly("org.projectlombok:lombok:1.18.12")
    testAnnotationProcessor("org.projectlombok:lombok:1.18.12")
}

configure<JavaPluginConvention> {
    sourceCompatibility = JavaVersion.VERSION_11
}

my module-info.java file

module my.module.main {
    requires static lombok;
}

After a while, I found out that the problem is I didn't turn on module path inference explicitly in the Gradle build file as stated in here

Add this to the gradle.build.kts file:

plugins.withType<JavaPlugin>().configureEach {
    configure<JavaPluginExtension> {
        modularity.inferModulePath.set(true)
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM