英文:
Why am I getting java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor error?
问题
我知道有其他类似的问题,但我已经浏览了所有这些问题,没有一个对我有用,所以我在这里提问。
我正在使用gradle进行我的项目,当我构建时,它构建成功,但当我尝试使用以下命令进行编译时:
./gradlew app:compileJava
我收到以下错误:
执行任务 ':app:compileJava' 失败。
> java.lang.IllegalAccessError: 类 lombok.javac.apt.LombokProcessor(在未命名的模块中...)无法访问类 com.sun.tools.javac.processing.JavacProcessingEnvironment(在模块 jdk.compiler 中)因为模块 jdk.compiler 不导出 com.sun.tools.javac.processing 到未命名的模块...
我的lombok依赖目前如下:
dependencies {
annotationProcessor 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
...
}
我也尝试过像这样为依赖项添加特定版本号:
annotationProcessor 'org.projectlombok:lombok:1.18.20'
但我仍然收到相同的错误。
我正在使用jdk 15(尝试过使用17、16和11,都出现相同的错误)。
当我在IntelliJ中检查我的注解处理器时,我看到有一个处理器路径,其中lombok的版本是1.18.16。我不知道这是否可能是问题,但当我删除.gradle文件夹中的缓存后,重新构建后,它会再次弹出。这里是一张截图。
请帮助,将不胜感激。
英文:
I know there are other similar questions like this, but I have gone through all of them, and none worked for me, hence my asking it here.
I'm using gradle for my project, and when I build, it builds successfully, but when I try to compile using:
/gradlew app:compileJava
I get this error:
Execution failed for task ':app:compileJava'.
> java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module ...) 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 ...
My dependency for lombok currently looks like this:
dependencies {
annotationProcessor 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
...
}
I have also tried adding a specific version number to the dependences like for example:
annotationProcessor 'org.projectlombok:lombok:1.18.20'
And I was still getting same error.
I'm using jdk 15 (tried using 17, 16 and 11, same error).
When I check my annotation processor in intelliJ, I see there is a processor path with lombok version 1.18.16. I don't know if this might be the issue, but when I delete the cache in .gradle folder, after building, it pops up again. Here is a screenshot.
Please any help would be really appreciated.
答案1
得分: 0
我最终所做的是将我的Java版本降级到8,但有一些包需要至少版本11才能正常运行。因此,我在我的build.gradle中添加了以下内容:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
注意:为了使此操作正常工作,您应该安装版本11和8两者。
英文:
So what I finially did, was to downgrade my java version to 8, but there are some packages that requires at least version 11 to function. So I added this in my build.gradle:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
Note: You should have both version 11 Nand 8 installed for this to work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论