SonarQube can't find unused imports when using Lombok's @Getter and @Setter

Viewed 43

When using lombok's generated getters and setters methods the unused imports are not detected.

Example:

@Entity
@Getter
@Setter
public class HomeMessage {

    ...
    private String message;
}
import java.io.File; // unused import
import org.springframework.web.bind.annotation.PostMapping; // unused import

@RestController
public class HomeController {

    @Autowired
    HomeRepository homeRepository;

    @GetMapping("/")
    public String helloWorld() {
        return homeRepository.getReferenceById(1L).getMessage();
    }
}

Full working code here: https://github.com/cod-r/spring-boot

Because I'm calling the .getMessage() method, which is generated by lombok, the unused imports are not detected by sonarqube.

If I remove the @Getter and @Setter annotations, and create the methods manually then the unused imports will be detected.

I tried to set sonar.java.libraries without luck:

<sonar.java.libraries>${user.home}/.m2/repository/org/projectlombok/lombok/**/*.jar</sonar.java.libraries>

Spring Boot 2.7.3
Lombok 1.18.24
Java 17
SonarQube 9.6-community

Anyone has any solution for this?

1 Answers

try config like this in your sonar.properties:sonar.java.binaries=target/classes

Related