欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java10下编译lombok注解代码分享

程序员文章站 2023-11-29 16:19:22
序 本文主要研究下在带有lombok(1.16.20版本)注解的代码在java10下的编译问题。 问题 fatal error compiling...


本文主要研究下在带有lombok(1.16.20版本)注解的代码在java10下的编译问题。

问题

fatal error compiling
  at org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:216)
  at org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:153)
  at org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:145)
  at org.apache.maven.lifecycle.internal.lifecyclemodulebuilder.buildproject(lifecyclemodulebuilder.java:116)
  at org.apache.maven.lifecycle.internal.lifecyclemodulebuilder.buildproject(lifecyclemodulebuilder.java:80)
  at org.apache.maven.lifecycle.internal.builder.singlethreaded.singlethreadedbuilder.build(singlethreadedbuilder.java:51)
  at org.apache.maven.lifecycle.internal.lifecyclestarter.execute(lifecyclestarter.java:128)
  at org.apache.maven.defaultmaven.doexecute(defaultmaven.java:307)
  at org.apache.maven.defaultmaven.doexecute(defaultmaven.java:193)
  at org.apache.maven.defaultmaven.execute(defaultmaven.java:106)
  at org.apache.maven.cli.mavencli.execute(mavencli.java:862)
  at org.apache.maven.cli.mavencli.domain(mavencli.java:286)
  at org.apache.maven.cli.mavencli.main(mavencli.java:197)
  at java.base/jdk.internal.reflect.nativemethodaccessorimpl.invoke0(native method)
  at java.base/jdk.internal.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)
  at java.base/jdk.internal.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)
  at java.base/java.lang.reflect.method.invoke(method.java:564)
  at org.codehaus.plexus.classworlds.launcher.launcher.launchenhanced(launcher.java:289)
  at org.codehaus.plexus.classworlds.launcher.launcher.launch(launcher.java:229)
  at org.codehaus.plexus.classworlds.launcher.launcher.mainwithexitcode(launcher.java:415)
  at org.codehaus.plexus.classworlds.launcher.launcher.main(launcher.java:356)
caused by: org.apache.maven.plugin.mojoexecutionexception: fatal error compiling
  at org.apache.maven.plugin.compiler.abstractcompilermojo.execute(abstractcompilermojo.java:1086)
  at org.apache.maven.plugin.compiler.compilermojo.execute(compilermojo.java:168)
  at org.apache.maven.plugin.defaultbuildpluginmanager.executemojo(defaultbuildpluginmanager.java:134)
  at org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:208)
  ... 20 more
caused by: org.codehaus.plexus.compiler.compilerexception: java.lang.exceptionininitializererror
  at org.codehaus.plexus.compiler.javac.javaxtoolscompiler.compileinprocess(javaxtoolscompiler.java:173)
  at org.codehaus.plexus.compiler.javac.javaccompiler.performcompile(javaccompiler.java:174)
  at org.apache.maven.plugin.compiler.abstractcompilermojo.execute(abstractcompilermojo.java:1075)
  ... 23 more
caused by: java.lang.runtimeexception: java.lang.exceptionininitializererror
  at jdk.compiler/com.sun.tools.javac.api.javactaskimpl.handleexceptions(javactaskimpl.java:158)
  at jdk.compiler/com.sun.tools.javac.api.javactaskimpl.docall(javactaskimpl.java:96)
  at jdk.compiler/com.sun.tools.javac.api.javactaskimpl.call(javactaskimpl.java:90)
  at org.codehaus.plexus.compiler.javac.javaxtoolscompiler.compileinprocess(javaxtoolscompiler.java:126)
  ... 25 more
caused by: java.lang.exceptionininitializererror
  at lombok.javac.handlers.handlegetter.<clinit>(handlegetter.java:303)
  at java.base/java.lang.class.forname0(native method)
  at java.base/java.lang.class.forname(class.java:374)
  at lombok.core.spiloadutil$1$1.next(spiloadutil.java:111)
  at lombok.javac.handlerlibrary.loadannotationhandlers(handlerlibrary.java:171)
  at lombok.javac.handlerlibrary.load(handlerlibrary.java:156)
  at lombok.javac.javactransformer.<init>(javactransformer.java:44)
  at lombok.javac.apt.lombokprocessor.init(lombokprocessor.java:89)
  at lombok.core.annotationprocessor$javacdescriptor.want(annotationprocessor.java:87)
  at lombok.core.annotationprocessor.init(annotationprocessor.java:140)
  at lombok.launch.annotationprocessorhider$annotationprocessor.init(annotationprocessor.java:69)
  at jdk.compiler/com.sun.tools.javac.processing.javacprocessingenvironment$processorstate.<init>(javacprocessingenvironment.java:674)
  at jdk.compiler/com.sun.tools.javac.processing.javacprocessingenvironment$discoveredprocessors$processorstateiterator.next(javacprocessingenvironment.java:771)
  at jdk.compiler/com.sun.tools.javac.processing.javacprocessingenvironment.discoverandrunprocs(javacprocessingenvironment.java:866)
  at jdk.compiler/com.sun.tools.javac.processing.javacprocessingenvironment.access$2100(javacprocessingenvironment.java:110)
  at jdk.compiler/com.sun.tools.javac.processing.javacprocessingenvironment$round.run(javacprocessingenvironment.java:1202)
  at jdk.compiler/com.sun.tools.javac.processing.javacprocessingenvironment.doprocessing(javacprocessingenvironment.java:1311)
  at jdk.compiler/com.sun.tools.javac.main.javacompiler.processannotations(javacompiler.java:1250)
  at jdk.compiler/com.sun.tools.javac.main.javacompiler.compile(javacompiler.java:928)
  at jdk.compiler/com.sun.tools.javac.api.javactaskimpl.lambda$docall$0(javactaskimpl.java:100)
  at jdk.compiler/com.sun.tools.javac.api.javactaskimpl.handleexceptions(javactaskimpl.java:142)
  ... 28 more
caused by: java.lang.classnotfoundexception: com.sun.tools.javac.code.typetags
  at java.base/java.lang.classloader.findclass(classloader.java:711)
  at java.base/java.lang.classloader.loadclass(classloader.java:566)
  at lombok.launch.shadowclassloader.loadclass(shadowclassloader.java:422)
  at java.base/java.lang.classloader.loadclass(classloader.java:499)
  at java.base/java.lang.class.forname0(native method)
  at java.base/java.lang.class.forname(class.java:291)
  at lombok.javac.javactreemaker$schroedingertype.getfieldcached(javactreemaker.java:156)
  at lombok.javac.javactreemaker$typetag.typetag(javactreemaker.java:245)
  at lombok.javac.javac.<clinit>(javac.java:155)
  ... 49 more

解决

这是当前1.16.20版本的问题,通过升级到最新snapshot版本1.16.21即可搞定,1.16.21的版本更新描述如下:

version: 1.16.21 (2018-03-29 11:54:42 utc)
v1.16.20 is the latest stable release of project lombok.
platform: fix for using lombok together with jdk9's new module-info.java feature. issue #985
platform: some initial work on supporting jdk10.
bugfix: potential fix for netbeans < 9. issue #1555
promotion: var has been promoted from experimental to the main package with no changes. the 'old' experimental one is still around but is deprecated, and is an alias for the new main package one. var documentation.
old-cruft: lombok.experimental.builder and lombok.experimental.value are deprecated remnants of when these features were still in experimental. they are now removed entirely. if your project is dependent on an older version of lombok which still has those; fret not, lombok still processes these annotations. it just no longer includes them in the jar.

本地安装

mvn install:install-file -dfile=lombok-1.16.21.jar -dgroupid=org.lombokproject -dartifactid=lombok -dversion=1.16.21 -dpackaging=jar

更新依赖

<dependency>
      <groupid>org.projectlombok</groupid>
      <artifactid>lombok</artifactid>
      <version>1.16.21</version>
      <scope>provided</scope>
    </dependency>

这样就大功告成了,如果大家在测试的时候还有任何疑问,可以在下方留言区讨论,感谢大家对的支持。