Lombok's @Getter is not generating getter methods for my entity.
I've tried writing getter myself and it works(but I don't want that obviously).
I've searched solutions on stackoverflow and most of the time problem was missing the lombok plugin but I do have it installed so I've eliminated that.
I also tried to uninstall it and then install it again but it didn't fix it.
I'm using the latest lombok verson.I'm sharing the code hoping someone will find the bug.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=".0.0" xmlns:xsi=";
xsi:schemaLocation=".0.0 .0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.kick-off</groupId>
<artifactId>kick-off</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>kick-off</name>
<description>Web app for organizing amateur football tournaments</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>21</java.version>
</properties>
<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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- .jsonwebtoken/jjwt-api -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.12.6</version>
</dependency>
<!-- .jsonwebtoken/jjwt-impl -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.12.6</version>
<scope>runtime</scope>
</dependency>
<!-- .jsonwebtoken/jjwt-jackson -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.12.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>6.3.3</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>6.3.3</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>6.3.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<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>
Entity
// using Integer because of testing phase I'm not population all of the fields with data.sql
so I get an error
@Entity
@Getter
@Setter
@Table(name = "teams")
public class Team {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "team_name")
private String teamName;
@Column(name = "coach")
private String coach;
@Column(name = "matches_played")
private Integer matchesPlayed;
@Column(name = "wins")
private Integer wins;
@Column(name = "draws")
private Integer draws;
@Column(name = "losses")
private Integer losses;
@Column(name = "goals_scored")
private Integer goalsScored;
@Column(name = "goals_against")
private Integer goalsAgainst;
@Column(name = "poIntegers")
private Integer poIntegers;
@Column(name = "established")
private Date established;
@Column(name = "photo_url")
private String photoUrl;
@OneToMany(mappedBy = "team")
private List<Player> players;
@ManyToMany(mappedBy = "teams")
private List<Tournament> tournaments;
@ManyToMany
@JoinTable(
name = "team_match",
joinColumns = @JoinColumn(name = "team_id"),
inverseJoinColumns = @JoinColumn(name = "match_id")
)
private List<Match> matches;
}
[
{},
{},
{},
{}
]
@RestController
@RequestMapping("/team")
public class TeamController {
private final TeamService teamService;
public TeamController(TeamService teamService) {
this.teamService = teamService;
}
@GetMapping
public ResponseEntity<List<Team>> fetchAllTeams() {
return new ResponseEntity<>(teamService.getAllTeams(), HttpStatus.OK);
}
}
Edit: I don't understand why I got a downvote on the post it's a legit question.I think my question was pretty clear and not unessential but ok.
FIX:When IntelliJ updated everything works fine now. Found a solution here /
Lombok's @Getter is not generating getter methods for my entity.
I've tried writing getter myself and it works(but I don't want that obviously).
I've searched solutions on stackoverflow and most of the time problem was missing the lombok plugin but I do have it installed so I've eliminated that.
I also tried to uninstall it and then install it again but it didn't fix it.
I'm using the latest lombok verson.I'm sharing the code hoping someone will find the bug.
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.kick-off</groupId>
<artifactId>kick-off</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>kick-off</name>
<description>Web app for organizing amateur football tournaments</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>21</java.version>
</properties>
<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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.12.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-impl -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.12.6</version>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-jackson -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.12.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>6.3.3</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>6.3.3</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>6.3.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<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>
Entity
// using Integer because of testing phase I'm not population all of the fields with data.sql
so I get an error
@Entity
@Getter
@Setter
@Table(name = "teams")
public class Team {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "team_name")
private String teamName;
@Column(name = "coach")
private String coach;
@Column(name = "matches_played")
private Integer matchesPlayed;
@Column(name = "wins")
private Integer wins;
@Column(name = "draws")
private Integer draws;
@Column(name = "losses")
private Integer losses;
@Column(name = "goals_scored")
private Integer goalsScored;
@Column(name = "goals_against")
private Integer goalsAgainst;
@Column(name = "poIntegers")
private Integer poIntegers;
@Column(name = "established")
private Date established;
@Column(name = "photo_url")
private String photoUrl;
@OneToMany(mappedBy = "team")
private List<Player> players;
@ManyToMany(mappedBy = "teams")
private List<Tournament> tournaments;
@ManyToMany
@JoinTable(
name = "team_match",
joinColumns = @JoinColumn(name = "team_id"),
inverseJoinColumns = @JoinColumn(name = "match_id")
)
private List<Match> matches;
}
[
{},
{},
{},
{}
]
@RestController
@RequestMapping("/team")
public class TeamController {
private final TeamService teamService;
public TeamController(TeamService teamService) {
this.teamService = teamService;
}
@GetMapping
public ResponseEntity<List<Team>> fetchAllTeams() {
return new ResponseEntity<>(teamService.getAllTeams(), HttpStatus.OK);
}
}
Edit: I don't understand why I got a downvote on the post it's a legit question.I think my question was pretty clear and not unessential but ok.
FIX:When IntelliJ updated everything works fine now. Found a solution here https://www.reddit.com/r/SpringBoot/comments/1hhk8at/even_after_lombok_dependency_and_plugin_i_cant/
You probably create this project through spring initializr. Spring Initialzr added annotationProcessorPaths in your pom.xml file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
In intelij Idea, you can press enable annotation processing and select Obtain processors from project classpath. Or you can remove annotationProcessorPath configuration from your pom.xml