简体   繁体   中英

vs code did not recognize lombok

I have an issue with my editor vscode. Recently we decided to use Lombok, but the problem that vscode did not recognize getters and setters generated by Lombok I did install the Lombok extension, but what I don't understand when I run the app it works perfectly.

Assumed you're using the extension Lombok Annotations Support for VS Code , from its official page:

Lombok added as a dependency in your Java Project (Make sure you're using the latest version to avoid issues!) Add with Maven or Add with Gradle

If you're coding in Maven project, add the lombok dependency in pom.xml:

在此处输入图像描述

If you're coding in no build tools project, download lombok.jar then add it to referenced libraries:

在此处输入图像描述

Because the compiler and the editor handle Lombok in different ways. The compiler takes Lombok dependency definition(in maven, gradle, etc..) and generates code(getters, setters, constructors) in final bytecode according to usages of Lombok annotations and compile program works perfectly(check the compiled code in a text editor.).

But the editor can not know things after the compilation like generated codes( AOP ) and etc...

An editor needs the plugin and a valid configuration. It seems in version 1.0.1 of VS Code Lombok extension autocomplete works perfectly but listing errors and warnings need some fixes.

Try this fix but don't forget VS Code Lombok extension project has not been maintained for 16 months, try to use older Java versions.

Mine solved in an unexpect way, The item java.jdt.ls.vmargs in my global setting.json is overwritten in the project-level setting.json, which is located in ${project.dir}/.vscode . It recovers when I delete project-level setting item.

I might accept some of vscode's suggestions popped up in the bottom right corner

A note appeared on the VS Code Lombok plugin:

Starting from 1.8.0, the Language Support for Java(TM) by RedHat extension has built-in support for Lombok and automatically uses the lombok.jar from your project classpath. The embedded lombok.jar in the vscode-lombok extension will be deprecated in favor of RedHat Java extension.

There's a settings in settings.json to control this feature:

"java.jdt.ls.lombokSupport.enabled": true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM