Step 1: enable the annotation processing
Go to Preferences -> Build, Execution, Deployment -> Compiler -> Annotation Processors and make sure of the following:
- Enable annotation processing box is checked
- Obtain processors from project classpath option is selected
Step 2: install the plugin Lombok
Step 3: install the dependency
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
Step 4: test
User.java
@Getter
@Setter
public class User {
public int id;
public String firstName;
public String lastName;
}
UserTest.java
public class UserTest {
@Test
public void givenAnnotatedUser_thenHasGettersAndSetters() {
User user = new User();
user.setFirstName("Test");
assertEquals("Test", user.getFirstName());
}
}