Issue
I have an entity class in my src/main/java directory like this:
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Student {
private String firstName;
private String lastName;
@Column(name = "email_address",
nullable = false
)
private String emailId;
private String gaurdianName;
private String gaurdianEmail;
private String gaurdianMobile;
}
In my test class in src/test/java directory I don't have access to Lombok features in my above class like setters and getters, builder methods and other features of Lombok.
Where is the problem?
In my test class I want to make an object of student class with builder method or use getter and setter methods like this:
Student student = new Student();
student.setFirstName("John"); // it doesn't work
student.getFirstName(); // it doesn't work
Student student = Student.builder().firstName("JOHN").build(); // it doesn't work
Here is my pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Solution
First check you have installed lombok plugin and enabled Enable annotation processing in your IDE settings ,Then check your your pom file and your lombok dependency scope .it should be provided
Answered By - Pouria Saleh
Answer Checked By - Willingham (JavaFixing Volunteer)