英文:
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
> 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;
}
答案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<JavaPlugin>().configureEach {
configure<JavaPluginExtension> {
modularity.inferModulePath.set(true)
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论