30

I downloaded the following project and imported it into Visual Studio Code:

https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example

I have a problem on the following class, when invoking: car.getName().

https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example/blob/d5c959162ed0f862a5dceb93f5957f92e052e062/server/src/main/java/com/okta/developer/demo/CoolCarController.java

which content is:

CoolCarController.java

package com.okta.developer.demo;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.stream.Collectors;

@RestController
class CoolCarController {
    private CarRepository repository;

    public CoolCarController(CarRepository repository) {
        this.repository = repository;
    }

    @GetMapping("/cool-cars")
    @CrossOrigin(origins = "http://localhost:4200")
    public Collection<Car> coolCars() {
        return repository.findAll().stream()
                .filter(this::isCool)
                .collect(Collectors.toList());
    }

    private boolean isCool(Car car) {
        return !car.getName().equals("AMC Gremlin") &&
                !car.getName().equals("Triumph Stag") &&
                !car.getName().equals("Ford Pinto") &&
                !car.getName().equals("Yugo GV");
    }
}

here is also the content of:

Car.java

package com.okta.developer.demo;

import lombok.*;

import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.Entity;

@Entity
@Getter @Setter
@NoArgsConstructor
@ToString @EqualsAndHashCode
public class Car {
    @Id @GeneratedValue
    private Long id;
    private @NonNull String name;
}

As you can see on the image below, I'm getting the error:

[Java] The method getName() is undefined for the type Car

enter image description here

I think Visual Studio Code doesn't understand the package: lombok.

Any idea on how can I make Visual Studio Code understand that package?

Thanks!

davidesp
  • 3,743
  • 10
  • 39
  • 77

2 Answers2

49

Ok, Installing extension: Lombok Annotations Support for VS Code (gabrielbb.vscode-lombok) did the trick.

davidesp
  • 3,743
  • 10
  • 39
  • 77
  • 4
    It haven't worked for me. I installed the extension and it sorted out the editor's Intellisense but not the compilation itself. I've got the _"Build Failed, do you want to continue?"_ error message when trying to run the code from within VSCode. If I choose _"Proceed"_, end up with the Error **Unresolved compilation problem**. Multiple Constructors and Methods are undefined. – dbaltor Aug 19 '19 at 10:55
  • 1
    I had the same issue as @dbaltor. I updated the VS Code to the latest and the lombok issues are gone. It's compiling fine without any issues. – Suresh Nov 14 '19 at 17:18
  • As @Suresh said, I updated to the last version of VS Code and then clearing the Workspace cache (by clicking on the Fix button when trying to running the app) did the trick. I also had installed the extension Lombok Annotations Support for VS Code. – mromagnoli Jun 08 '20 at 12:48
45

If your project loads before installing this plugin Lombok Annotations Support for VS Code, you can run this command in vscode to reload the project.

Press Command + shift + P and execute:

Java: Clean Java language server workspace
Arman
  • 1,019
  • 2
  • 14
  • 33
Ringtail
  • 611
  • 6
  • 4