Lombok模块在Java 11和Gradle中未找到。

huangapple go评论41阅读模式
英文:

Lombok module not found with Java 11 and Gradle

问题

目前,我无法使这个项目运行起来,不知何故,Gradle 找不到 Lombok 模块。我正在使用以下版本:

  • Lombok 版本 1.18.12
  • OpenJDK 11.0.8
  • Gradle 6.4

根据这个GitHub 问题,问题应该在这个版本中得到解决,但对我来说并没有起作用。

以下是错误信息:

> 任务 :Model-library:compileJava 失败
/home/dauto98/path..to..project/src/main/java/module-info.java:2: 错误: 未找到模块: lombok
    requires static lombok;

下面是我的 gradle.build.kts 文件:

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
}

我的 module-info.java 文件:

module my.module.main {
    requires static lombok;
}
英文:

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

&gt; 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 = &quot;org.example&quot;
version = &quot;1.0-SNAPSHOT&quot;

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(&quot;junit&quot;, &quot;junit&quot;, &quot;4.12&quot;)

    compileOnly(&quot;org.projectlombok:lombok:1.18.12&quot;)
    annotationProcessor(&quot;org.projectlombok:lombok:1.18.12&quot;)

    testCompileOnly(&quot;org.projectlombok:lombok:1.18.12&quot;)
    testAnnotationProcessor(&quot;org.projectlombok:lombok:1.18.12&quot;)
}

configure&lt;JavaPluginConvention&gt; {
    sourceCompatibility = JavaVersion.VERSION_11
}

my module-info.java file

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

答案1

得分: 0

在一段时间后,我发现问题出在我没有像这里所述那样,在Gradle构建文件中明确启用模块路径推断。

将以下内容添加到gradle.build.kts文件中:

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

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&lt;JavaPlugin&gt;().configureEach {
    configure&lt;JavaPluginExtension&gt; {
        modularity.inferModulePath.set(true)
    }
}

huangapple
  • 本文由 发表于 2020年7月30日 01:46:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63159540.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定