Lombok Dependency

https://projectlombok.org/

NOTE: It is assumed you have gone through Zero Dependency Demo First.

Essentially your Maven repository of external JAR dependencies gets added with new <projectSpecific>.jar and adds its mention in your pom.xml file, for all dependencies SELECTED while Spring Booting.

Rest of the things (JRE libraries and src, test, files) remains more or less same.

Click on ADD DEPENDENCY this time and choose Lombok Project. (It is nothing but annotation project for getter / setter methods & constructor of your any POJO). Putting @Data before class and putting @Getter / @Setter before methods will define getter setters internally. Why this? It makes code cleaner and more readable.

Download zip by clicking on GENERATE. Open as project in Eclipse.

Before you create POJO, make sure Lombok JAR file is configured in your Eclipse. How to check? Click on HELP >> About and see if About dialog box shows Lombok as below.

Do not worry / panic if you didn’t get that. It only means you have to configure it in Eclipse as plug-in just for once.

Click on Install / Update


Now that you have made sure Lombok is configured on your Eclipse, create an annotated Employee POJO.

package in.janisoftwares.lombok;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

public @Data class Employee {
	private @Getter @Setter int empId;
	private @Getter @Setter String empName;
}

Modify your application file.

package in.janisoftwares.lombok;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class LombokApplication {

	public static void main(String[] args) {
		SpringApplication.run(LombokApplication.class, args);
		Employee e = new Employee();
		e.setEmpId(1);
		e.setEmpName("Janardan");
		System.out.println("Using LOMBOK dependency.");
		System.out.println("Employee ID = " + e.getEmpId());
		System.out.println("Employee Name = " + e.getEmpName());
	}
}

Run the application (the one that contains main() method)

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.4)

2021-09-09 14:12:58.306  INFO 5164 --- [           main] i.j.lombok.LombokApplication             : Starting LombokApplication using Java 1.8.0_301 on JANISOFTWARES with PID 5164 (E:\root_d\Companies\Jani Softwares - Private Firm\Assignments\spring_boot\lombok\target\classes started by JANI PLASTIC in E:\root_d\Companies\Jani Softwares - Private Firm\Assignments\spring_boot\lombok)
2021-09-09 14:12:58.310  INFO 5164 --- [           main] i.j.lombok.LombokApplication             : No active profile set, falling back to default profiles: default
2021-09-09 14:12:59.224  INFO 5164 --- [           main] i.j.lombok.LombokApplication             : Started LombokApplication in 1.52 seconds (JVM running for 2.131)
Using LOMBOK dependency.
Employee ID = 1
Employee Name = Janardan

CONGRATULATIONS! Your Lombok Dependency Hello World Program runs.


Q. What to do if I want to add more dependencies?

No need to go back to https://start.spring.io/. That is just to get basic framework in place. All you need is to add mention of correct JAR file in pom.xml and Maven will download the dependency for you.