Lombok-related errors on Visual Studio Code with the extension installed - java

I have decided I had enough of Eclipse's slowness and just moved everything to VSCode. I installed the java extension package as well as the Lombok extension.
My project worked perfectly fine in Eclipse and, although it does run fine, VSCode is finding thousands of errors obviously related to not finding the getter/setter methods that Lombok generates. My solution consists of two projects that both depend on a class library (the third project) which has a dependency for Lombok registered.
How can I get rid of these errors / make Lombok work properly in VSCode?

Seems like my issue was loading the 3 projects into my workspace before installing the Lombok plugin. I have removed the projects from my workspace and opened them again and the errors are gone.

here the other way to clean the getter/setter errors :
under "Java Projects" section -> click "..."
Click "Clean Workspace"
wait the clean up process
it will reload the code and no more getter/setter errors

The above works but of course make sure you have the VS Code lombok plugin installed.
press Ctrl + Shift + X to open the extension manager.
Type lombok to find the plugin, and click install.
Reload VS Code.

Related

Visual Studio Code + Java - doesn't find my dependencies from build.gradle.kts

Visual Studio Code doesn't resolve dependencies declared in my build.gradle.kts file in this test project. Can you help me see what I'm doing wrong?
I'm using the newest VScode (downloaded 1.52.1 yesterday), and I've started from a clean install by deleting %APPDATA%\Code and %USERPROFILE%\.vscode before starting VScode.
When opening up my Java file and installing various suggested extensions (see below), I end up seeing The import org.keycloak cannot be resolved:
which is true for any dependencies from build.gradle.kts. Notice how java.util.List is fine.
gradle builds the project fine, even from within VScode:
Also, "Java Projects" shows "Referenced Libraries" as empty:
I suspect that an empty "Referenced Libraries" is related to not resolving org.keycloak above.
The exact same project is fine when opened in Intellij.
I've used this test project, and after installing various suggested extensions, I ended up with this list from code --list-extensions:
fwcd.kotlin
mathiasfrohlich.Kotlin
ms-vscode-remote.remote-wsl
naco-siren.gradle-language
redhat.java
richardwillis.vscode-gradle
richardwillis.vscode-gradle-extension-pack
VisualStudioExptTeam.vscodeintellicode
vscjava.vscode-java-debug
vscjava.vscode-java-dependency
vscjava.vscode-java-pack
vscjava.vscode-java-test
vscjava.vscode-maven
Edit: I've tried following https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting. I looked at Developer: Toggle Developer Tools where I didn't see anything obviously related to my problem, although I'm not sure what I was looking for. (I've saved the log from developer tools, but warning: The saved file's formatting is not easy to read...) I also tried to run Java: Clean the Java language server workspace and that didn't help either.
Update on 8/26/2021
It's now supported! See: https://github.com/redhat-developer/vscode-java/issues/632#issuecomment-905715322
Gradle *.kts files are not supported right now, which means your project is not recognized correctly.
See: https://github.com/redhat-developer/vscode-java/issues/632
I seem to have fixed it by referencing the gradle cache folder in my settings.json.
{
"java.configuration.updateBuildConfiguration": "automatic",
"java.project.referencedLibraries": [
"C:\\Users\\<UserName>\\.gradle\\caches\\**\\*.jar"
]
}

How to get lombok generated source to be visible in eclipse/maven?

I am attempting to use lombok (https://projectlombok.org/) to help with "boilerplate" code generation. I have added the maven dependency and have also added the lombok maven plugin to the <build> element in the POM.
One of the things I was also told to do was to place the lombok-annotated code in src/main/lombok instead of src/main/java. I assume that I keep the package directory structure the same as in src/main/java.
This seems a little odd, but I did this and lombok did generate source files with all the getter/setter/equals/hashCode etc methods. They are placed in e.g. target/generated-sources/lombok/x/y/z/MyClass.java. This is kind of what I would expect having used other code generation tools like XJC.
My question is: how do I get this generated source to be "visible" to eclipse and the compile environment? I'm getting compile errors all over the place because it can't "see" the generated code. This occurs in eclipse as well as when I attempt to do a mvn clean install.
UPDATE:
I have already tried installing lombok into eclipse. It generates the getters/setters/etc, but there is a bug introduced somewhere that breaks the auto-complete feature of eclipse. I removed it from eclipse and am just trying to get maven to do the generation (or delombok-ing).
I've just installed Lombok (after a while) in my new Eclipse (STS) installation, and i was a bit "annoyed" by the lack of generated sources.
I found a hint however on this page that the generated structure is visible in the "Outline" view. (Look for the screenshots)
If you don't have Outline view open yet, enable it in the menu: Window / Show view / Outline.
Download Lombok jar (https://projectlombok.org/download) and execute it java -jar lombok.jar and select your eclipse installed folder.Restart eclipse and rebuild project.
To verify Lombok installation, please check Help -> About eclipse. Lombok entry show show at bottom.
You have to enable annotation processing for Eclipse to be able to pick up generated code.
Right-click on the project and select Properties.
Open Java Compiler and then Annotation Processing. Check Enable
annotation processing.
Open Java Compiler -> Annotation Processing -> Factory Path. Check
Enable project specific settings. Add your Lombok JAR file to the list.
Clean and build the project.
My problem was using full namespace annotation: #lombok.Getter, and I resolved it by doing import lombok.Getter and do #Getter

Maven + IDEA: cannot find String

I am trying out the workflow where you create and maintain your project primarily in Maven, and the Intellij IDEA project files are derived from that, which seems to be the recommended way these days.
My setup: Windows 7, JDK 11, Maven 3.6.0, IDEA Community 2018.2.6, the latter three all fairly fresh installs, not messed around with, verified as working in their own right.
https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html followed steps to create a Hello World project, verified it compiles and runs with Maven after adding the project property entries to specify we are not on Java 5 anymore.
Opened the project in IDEA by opening pom.xml and saying yes, this is a project file.
Opened App.java, and references to String are underlined in red: Cannot resolve symbol 'String'.
Tried invalidate caches / restart, no change.
Consensus as far as I can tell is that maven is the top build system and IDEA is the top IDE, so it must be possible to get them to work together. How?
Open Project Structure (by pressing F4):
Check the SDKs and Problems sections for any error.

Google Eclipse plugin recompile problem

I have installed Eclipse Helios(3.6) and Google plugin to develope app in GAE/J.Then created project and runned it sucessufull. Later made some changes in source code but it doesnt recompiled. Previous compiled version is in use. It doesnt compile until I make changes in appengine-web.xml. Could you suggest how to solve the problem please?
PS : I had the same problem in Eclipse 3.5. Also I added javac to SYSTEMPATH.
You could try the following:
the folder where your java files are in is a "source folder" (check it via project properties, "build path")
turn on "build automatically"? Can be found in Menu "Project"
Maybe refreshing your workspace automatically will help (Window->Preferences, and search for workspace)
The Project is automatically not builded or recompiled, when there are problems marked by eclipse. Take a look into the marker panel of eclipse and solve the problems.

Package <blah> does not exist error - NetBeans 6.8 & Windows 7

I'm using NetBeans 6.8 on Windows 7. I upgraded from WinXP and NetBeans 6.7. Now my existing java web app project is no longer able to import/find the packages I've developed - I receive a 'Package ,blah. does not exist' and yet the packages do exist, worked fine in NetBeans 6.7 and the project still compiles and runs OK.
I've tried changing the Java Platform/JDK from 1.6.0_10 back to JDK 1.5.0_22 but I still receive errors package does not exist.
All other 'standard' libraries and packages are able to be imported and used OK ... eg Struts, Hibernate
I have fixed this problem many times by clearing the NetBeans cache.
1) Close NetBeans
2) Go to "C:\Users\.netbeans\6.8\var\cache
3) Delete everything that is in this directory
4) Open NetBeans and wait for it to re-scan your projects
At this time, this has fixed my problem. I do need to do this every once and a while, but if I don't change anything in the project's structure, the issue does not come back, and I can develop in peace!
Hope it helps someone in need.
Solution was to create a new empty web application, check the existing project out from SVN, regenerate the build-impl.xml & configure the library references.
All is now importing and referencing OK
I do not have an explanation as to why the problem occurred the first time this project was created
I had the same issue with Netbeans 7.0.1. Suddenly after some work I could not compile my project anymore, because a major package "does not exit" anymore. All my projects settings (build properties, project properties, dependencies ) seemed ok for me.
The only (bad) solution I could find is, to copy the relevant module to a new name, remove the old and re-create the module again by copy/paste of packages. Now it works again.
regards
I have seen the error when I had the same jar installed twice - as compile library and as a test library.
As the result, many of packages became invisible.
After removing the jar from compile libraries everything become visible.
In the project Properties, under "Libraries", "Compile" tab. Do an "Add jar/folder" of the "src" directory if it's a regular Java project. If it's JSF, use "src/java" instead.
just change s by S in System.out., is simple but i think is your problem

Categories

Resources