Vscode-java: Syntax checking doesn't work with Lombok

Created on 5 Jul 2018  ·  18Comments  ·  Source: redhat-developer/vscode-java

No syntax checking at all i.e Red squiggles or showing number of problems in the the workspace (bottom left corner of vscode). Intellisense works. Builds with Maven ok.

Environment
  • Operating System: macOS 10.13.5
  • JDK version: Oracle 10.0.1
  • Visual Studio Code version: 1.25.0-insider
  • Java extension version: 0.28.0
Steps To Reproduce
  1. Any Spring Boot, Maven project
  2. Add Lombok 1.18.0

Logs

WARNING: Using incubator modules: jdk.incubator.httpclient
[Error - 11:21:30] 5 Jul. 2018, 11:20:20 am Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
javax/annotation/processing/AbstractProcessor
java.lang.NoClassDefFoundError: javax/annotation/processing/AbstractProcessor
at java.base/java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.base/java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1250)
at java.base/java.lang.System$2.findBootstrapClassOrNull(System.java:2134)
at java.base/jdk.internal.loader.ClassLoaders$BootClassLoader.loadClassOrNull(ClassLoaders.java:130)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:617)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:617)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:553)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:553)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
at org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader.loadJava6FactoryClasses(AnnotationProcessorFactoryLoader.java:638)
at org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader.loadFactories(AnnotationProcessorFactoryLoader.java:577)
at org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader.getJava5FactoriesAndAttributesForProject(AnnotationProcessorFactoryLoader.java:417)
at org.eclipse.jdt.apt.core.internal.AptCompilationParticipant.processAnnotations(AptCompilationParticipant.java:188)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.processAnnotations(AbstractImageBuilder.java:642)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:352)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:76)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:259)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:177)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:795)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:216)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:259)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:312)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:315)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:367)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:388)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:142)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:232)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)

[Error - 11:21:33] 5 Jul. 2018, 11:20:20 am Errors occurred during the build.
[Error - 11:21:33] 5 Jul. 2018, 11:20:20 am Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
javax/annotation/processing/AbstractProcessor
java.lang.NoClassDefFoundError: javax/annotation/processing/AbstractProcessor
at java.base/java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.base/java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1250)
at java.base/java.lang.System$2.findBootstrapClassOrNull(System.java:2134)
at java.base/jdk.internal.loader.ClassLoaders$BootClassLoader.loadClassOrNull(ClassLoaders.java:130)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:617)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:617)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:553)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:553)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
at org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader.loadJava6FactoryClasses(AnnotationProcessorFactoryLoader.java:638)
at org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader.loadFactories(AnnotationProcessorFactoryLoader.java:577)
at org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader.getJava5FactoriesAndAttributesForProject(AnnotationProcessorFactoryLoader.java:417)
at org.eclipse.jdt.apt.core.internal.AptCompilationParticipant.processAnnotations(AptCompilationParticipant.java:188)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.processAnnotations(AbstractImageBuilder.java:642)
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:352)
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:76)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:259)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:182)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:795)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:216)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:259)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:312)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:315)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:367)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:388)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:142)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:232)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)

[Error - 11:21:33] 5 Jul. 2018, 11:20:20 am Errors occurred during the build.

Current Result

See intro

Expected Result

Syntax checking works when Lombok 1.18.0 is a dependency

Additional Informations

n/a

Lombok Maven bug

Most helpful comment

So I seem to have found a workaround.
@Fubuchi The difference between the gradle and maven projects is that Maven support in vscode-java/jdt.ls automatically detects annotation processors and enables Eclipse's annotation processing (JDT APT). Gradle support doesn't do that.
Running annotation processing when the server is started with Java>9 fails for lombok, due to rzwitserloot/lombok#1572.
The thing is, when lombok is added to the bootstrap path of the server, it plugs into JDT to perform the bytecode manipulation, outside the annotation processing mechanism, so we actually don't need to enable APT.

So you need to do a few things.

  • add <m2e.apt.activation>disabled</m2e.apt.activation> to your pom <properties> section
  • set org.eclipse.jdt.core.compiler.processAnnotations=disabled in .settings/org.eclipse.jdt.core.prefs
  • set org.eclipse.jdt.apt.aptEnabled=false in .settings/org.eclipse.jdt.apt.core.prefs
  • execute the Update project configuration command from the pom.xml context menu

All 18 comments

can you provide a sample project reproducing the issue?

Does it work from CLI? I found https://github.com/rzwitserloot/lombok/issues/1572 which shows issues with Java 10

@kalch, were you able to solve this issue? I'm getting the same issue unfortunately and haven't found an explanation or a workaround yet.

I wasn't able to. Didn't have time. Switched to IntelliJ.

I wasn't able to. Didn't have time. Switched to IntelliJ.

https://mvnrepository.com/artifact/org.projectlombok/lombok/1.12.6

This version is available.

I think there is a problem with the m2e plugin, I create 2 sample spring project from https://start.spring.io/ , one with maven, one with gradle and both have lombok + Spring JPA, only the maven project failed to build with VSCode (mvn install work file) and generate the same log as what @kalch has posted.

@Fubuchi please attach those projects here

Here is the maven and gradle projects, run Java: Force Java Compilation in the maven project produce the same error in log file. The maven spring boot project at my company build with VSCode without error, by monday, I will take a look at that project pom and other config to see if it can help.

demo.zip

So I seem to have found a workaround.
@Fubuchi The difference between the gradle and maven projects is that Maven support in vscode-java/jdt.ls automatically detects annotation processors and enables Eclipse's annotation processing (JDT APT). Gradle support doesn't do that.
Running annotation processing when the server is started with Java>9 fails for lombok, due to rzwitserloot/lombok#1572.
The thing is, when lombok is added to the bootstrap path of the server, it plugs into JDT to perform the bytecode manipulation, outside the annotation processing mechanism, so we actually don't need to enable APT.

So you need to do a few things.

  • add <m2e.apt.activation>disabled</m2e.apt.activation> to your pom <properties> section
  • set org.eclipse.jdt.core.compiler.processAnnotations=disabled in .settings/org.eclipse.jdt.core.prefs
  • set org.eclipse.jdt.apt.aptEnabled=false in .settings/org.eclipse.jdt.apt.core.prefs
  • execute the Update project configuration command from the pom.xml context menu

@fbricon Confirm it fix the issue. Code can compile without error now.

@fbricon Can confirm this workaround works (MacOS).

Reproduced using:
openjdk version "11.0.3" 2019-04-16
Spring Boot 2.2.0M1
VS Code Java Debugger

However, except the Lombok syntax checking, the debugger did not work for me at all. It crashed with
"Could not find or load main class" exception
@fbricon's fix did the trick

The fix above from @fbricon worked for me as well. It is a very obscure problem, because I just got a "Could not find or load main class" exception like @eenchev. Only looking at the error in the VSCode Java language server log led me to this thread when I find the AbstractProcessor error.

What is the official way to fix this so that people don't have to make these edits manually?

To get vscode to work with java and spring boot tools extensions...

  • I've deinstalled the vscode lombok extension.
  • Stopped vscode.

  • After this I've downloaded the newest lombok.jar from https://projectlombok.org/

  • Then removed in ~/.config/Code/User/settings.json under java.jdt.ls.vmargs the Bootclasspath setting to lombok.jar

  • And adapted the javaagent path to my downloaded lombok.jar: -javaagent:/home/.../lombok.jar

  • Started vscode.

  • Last step Force Java Compilation.

I don't need the above settings from @fbricon https://github.com/redhat-developer/vscode-java/issues/580#issuecomment-443302372
These make problems with spring boot and java test runner.

Thank you so much @fbrico and @kolbma , your insights helped me solve my long standing problem of getting syntax checking working in Emacs (using lsp-java, and flycheck). I was chasing the wrong problem (java.lang.NoClassDefFoundError: javax/annotation/processing/AbstractProcessor) and you got me onto the right path.

Closing issue. Thanks everyone.

@kolbma I fixed the issue in the VSCode Lombok extension. You can reinstall it if you want to

https://github.com/redhat-developer/vscode-java/issues/580#issuecomment-486483938
完美的解决了,我使用vscode开发java应用程序时lombok找不到log的问题

So I seem to have found a workaround.
@Fubuchi The difference between the gradle and maven projects is that Maven support in vscode-java/jdt.ls automatically detects annotation processors and enables Eclipse's annotation processing (JDT APT). Gradle support doesn't do that.
Running annotation processing when the server is started with Java>9 fails for lombok, due to rzwitserloot/lombok#1572.
The thing is, when lombok is added to the bootstrap path of the server, it plugs into JDT to perform the bytecode manipulation, outside the annotation processing mechanism, so we actually don't need to enable APT.

So you need to do a few things.

  • add <m2e.apt.activation>disabled</m2e.apt.activation> to your pom <properties> section
  • set org.eclipse.jdt.core.compiler.processAnnotations=disabled in .settings/org.eclipse.jdt.core.prefs
  • set org.eclipse.jdt.apt.aptEnabled=false in .settings/org.eclipse.jdt.apt.core.prefs
  • execute the Update project configuration command from the pom.xml context menu

It works - thank you very much.
Maybe someone have an idea how to avoid making changes in project's pom? I would like to avoid changing projects I'm working on only to adjust them to my development environment setup.

Was this page helpful?
0 / 5 - 0 ratings