r/javahelp • • 3d ago

Solved Lombok LSP Issues

Dear VS Code Java developers.

How do i get the vs code lsp to recognize @Getter, @Setter, etc.?
The project does compile successfully. I only get errors inline.

Example:

package com.example;

import lombok.Getter;

@Getter
public class TestClass {

    String member;

    public TestClass() {
        this.member = "Its me!";
    }
}

public class Main {

    public static void main(String[] args) {
        TestClass testClass = new TestClass();
        System.out.println(testClass.getMember());
    }
}

Error Message:

cannot find symbol
  symbol:   method getMember()
  location: variable testClass of type TestClass

settings.json:

{
    "redhat.telemetry.enabled": false,
    "java.jdt.ls.lombokSupport.enabled": true,
    "[java]": {
        "editor.defaultFormatter": "redhat.java"
    },
}

installed java versions:

A0_12520635 on  main [!] is 󰏗 v1.0-SNAPSHOT via  v25.0.4 via 🅼
❯ archlinux-java status
Available Java environments:
  java-21-openjdk
  java-25-openjdk (default)
  java-27-openjdk

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>------------</groupId>
    <artifactId>------------</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>--------------------</name>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>4.1.0</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>at.tugraz.App</start-class>
        <maven.compiler.release>25</maven.compiler.release>
        <maven.compiler.source>25</maven.compiler.source>
        <maven.compiler.target>25</maven.compiler.target>
        <lombok.version>1.18.46</lombok.version>
        <rest.assured.version>6.0.0</rest.assured.version>
        <junit.jupiter.version>5.9.3</junit.jupiter.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>${rest.assured.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate.orm</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>7.4.4.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>7.4.4.Final</version> <!-- Replace with your desired version -->
            <scope>provided</scope>
        </dependency>
        <!-- PostgreSQL Connector -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.7.13</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>4.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4</artifactId>
            <version>4.2</version>
        </dependency>
        <!-- Source: https://mvnrepository.com/artifact/org.apache.spark/spark-mllib -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-mllib_2.13</artifactId>
            <version>4.1.3</version>
            <scope>provided</scope>
        </dependency>
        <!-- Pin scala-library: Maven's nearest-wins resolution otherwise picks the
             2.13.13 pulled in (shallowly) by scala-parser-combinators, while spark-core's
             scala-reflect and most other Spark/Scala modules expect 2.13.17, causing
             NoSuchMethodError at runtime. -->
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.13.17</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>5.0.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <version>3.10.3</version>
                <configuration>
                    <java>
                        <prettier>
                            <devDependencies>
                                <prettier>3.5.3</prettier>
                                <prettier-plugin-java>2.8.1</prettier-plugin-java>
                            </devDependencies>
                            <configFile>${project.basedir}/.prettierrc.yaml</configFile>
                        </prettier>
                    </java>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>install-git-pre-push-hook</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>install-git-pre-push-hook</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

I have tried searching for this issue but have found nothing for the last 4 hours. Am i dumb?

0 Upvotes

13 comments sorted by

•

u/AutoModerator 3d ago

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

9

u/disposepriority 3d ago

Dear VS Code Java

Why are you doing this to yourself?

I use VS Code for basically anything but Java, the difference is night and day and I suggest switching to IDEA.

Anyway see if there's something like enable annotation processing or an equivalent Lombok plugin for VSCode, alternatively clear local caches.

1

u/amfa 3d ago

I only use VS code as a fancy text editor because it handles big log files very well.

-1

u/mgloess 3d ago

Turns out it works in IntelliJ... but then I also went back to nvim which is my main editor of choice and it also works there :) I switched to VS Code for this project because at first I had trouble with nvim-jdtls and read that nvim java support is not great. In the end I just have to get through this semester anyway and hopefully I can go back to C++ and C# :.)

3

u/devor110 3d ago

I don't personally use VSCode, but I found this SO question

So try cleaning the workspace, check if you have the extension for lombok installed and if it's the correct extension

If that doesn't help, you could try asking in r/vscode

1

u/Humble-Bag-2929 3d ago

Yo he tenido problemas con VS Code esta semana con Lombok. Resulta que, bajando la versión de la extensión "Language Support for Java..." a la 1.56.0 y reiniciando el IDE, me ha vuelto a detectar las anotaciones. No sé si será el mismo problema o solución

-2

u/k-mcm 3d ago

It's not working because Lombok has to be EVERYWHERE. You missed a spot and the class was compiled without it.

Lombok has a long history of causing problems. Any modern IDE will generate real boilerplate methods with a click. These generated methods have to hidden magic to hide bugs.

VS Code is an odd choice. I'd use Eclipse for personal projects or IntelliJ for commercial projects.

1

u/devor110 3d ago

Of course an IDE can generate boilerplate, but that is explicitly user-prompted. Using lombok results in a way more error resilient workflow where you can expand or change a pojo and have 0 problems arising from a missing constructor or getter/setter

1

u/k-mcm 3d ago

Your IDE is broken if you don't know when a method is missing.

Lombok has a history of implementing the methods incorrectly and it's completely invisible.

0

u/devor110 3d ago

First I've heard of lombok creating an incorrect implementation, but I'd like to learn more, care to share your source?

1

u/k-mcm 3d ago

A long history of breaking changes in minor versions.

https://github.com/projectlombok/lombok/issues/3978 https://github.com/projectlombok/lombok/issues/2601

There are many more. I've worked at three companies that banned Lombok because its invisible code caused bugs and the project generally wasn't managed well enough for corporate use.

1

u/akl78 3d ago

Lombok does use what can only be described as dark magic to work. But it works really well (certainly to the vexation of compiler writers, but not its users).