0

一直在尝试设置 Immutables 库,但尽管遵循指南 Eclipse 似乎没有在 target/generated-sources/annotations 文件夹中生成任何类

这是java编译器的截图->注释处理设置

显示注释处理设置的屏幕截图

工厂路径显示根据 Immutables 指南选择了 Immutables value-2.8.2.jar - https://immutables.github.io/immutable.html

显示出厂路径设置的屏幕截图

我已经运行了 Project -> Clean 然后 Project -> Build All

我在错误日志中收到错误:Java 注释处理器 org.immutables.processor.ProxyProcessor@63924c86 引发的异常

和相应的堆栈跟踪

java.lang.Exception: java.lang.UnsupportedClassVersionError: org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl
at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:172)
at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:124)
at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:171)
at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:138)
at org.eclipse.jdt.internal.compiler.Compiler.processAnnotationsInternal(Compiler.java:958)
at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:932)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:450)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:386)
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.compile(IncrementalImageBuilder.java:371)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:318)
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.incrementalBuildLoop(IncrementalImageBuilder.java:190)
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:147)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:292)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:212)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:832)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:220)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:263)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:316)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:319)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:371)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:392)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:154)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:244)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.UnsupportedClassVersionError: org/eclipse/jdt/internal/compiler/apt/model/ModuleElementImpl
    at org.eclipse.jdt.internal.compiler.apt.model.PackageElementImpl.getEnclosingElement(PackageElementImpl.java:120)
    at org.immutables.value.internal.$processor$.meta.$ImportRewriteDisabler.shouldDisableFor($ImportRewriteDisabler.java:81)
    at org.immutables.value.internal.$processor$.meta.$ImportRewriteDisabler.shouldDisableFor($ImportRewriteDisabler.java:41)
    at org.immutables.value.internal.$processor$.meta.$ValueType.sourceHeader($ValueType.java:112)
    at org.immutables.value.internal.$processor$.$Generator_Immutables._t2__packageWhenTopLevel($Generator_Immutables.java:160)
    at org.immutables.value.internal.$processor$.$Generator_Immutables$FragmentDispatch.run($Generator_Immutables.java:19964)
    at org.immutables.value.internal.$generator$.$Templates$Fragment.invoke($Templates.java:248)
    at org.immutables.value.internal.$generator$.$Intrinsics.$($Intrinsics.java:96)
    at org.immutables.value.internal.$processor$.$Generator_Immutables._t4__generateImmutable($Generator_Immutables.java:320)
    at org.immutables.value.internal.$processor$.$Generator_Immutables$FragmentDispatch.run($Generator_Immutables.java:19966)
    at org.immutables.value.internal.$generator$.$Templates$Fragment.invoke($Templates.java:248)
    at org.immutables.value.internal.$generator$.$Intrinsics.$($Intrinsics.java:96)
    at org.immutables.value.internal.$processor$.$Generator_Immutables$1.run($Generator_Immutables.java:23)
    at org.immutables.value.internal.$generator$.$Templates$Fragment.invoke($Templates.java:248)
    at org.immutables.value.internal.$generator$.$Output$7.invoke($Output.java:177)
    at org.immutables.value.internal.$generator$.$Intrinsics.$($Intrinsics.java:96)
    at org.immutables.value.internal.$processor$.$Generator_Immutables._t0__generate($Generator_Immutables.java:20)
    at org.immutables.value.internal.$processor$.$Generator_Immutables$FragmentDispatch.run($Generator_Immutables.java:19962)
    at org.immutables.value.internal.$generator$.$Templates$Fragment.invoke($Templates.java:248)
    at org.immutables.value.internal.$generator$.$AbstractGenerator.invoke($AbstractGenerator.java:57)
    at org.immutables.value.internal.$processor$.$Processor.process($Processor.java:81)
    at org.immutables.value.internal.$generator$.$AbstractGenerator.process($AbstractGenerator.java:87)
    at org.immutables.processor.ProxyProcessor.process(ProxyProcessor.java:72)
    at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:142)
    ... 26 more

我究竟做错了什么?

4

1 回答 1

2

您的不可变 jar 太新或太旧(或者您用于运行 Eclipse 的 Java 版本太新或太旧)。

您可以在 Eclipse 中检查该 Java 版本:找到“关于 Eclipse”选项(在 Mac 上的 Eclipse 菜单下,我认为它在其他操作系统的“帮助”下),然后选择配置选项卡。检查java.home=....那里的条目,它将指向用于启动 Eclipse 本身的 JVM。那就是抛出那些错误,或者,不可变系统附带一个内部编译器(并且 ecj 通常是项目使用的 java 解析器,因为它是快速且开源的),在这种情况下,就是抛出错误的那个. 很难从堆栈跟踪中分辨出哪个是错误的。

所以,我会检查你的 immutables dep 的版本,如果它很旧,请更新它。然后我会检查你正在运行 eclipse 的虚拟机,如果它很旧,请更新它。

实际上,我会抛弃不可变对象而只使用 lombok,但是,我会:P

于 2020-12-10T15:14:23.153 回答