Skip to content

Instantly share code, notes, and snippets.

@matiasah
Created April 7, 2022 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matiasah/ada14c14a547385e7e14c318853a6020 to your computer and use it in GitHub Desktop.
Save matiasah/ada14c14a547385e7e14c318853a6020 to your computer and use it in GitHub Desktop.
How to remove Lombok Code Smells/Issues or findings from SonarQube

SpotBugs dependency

Add spotbugs-annotations dependency https://mvnrepository.com/artifact/com.github.spotbugs/spotbugs-annotations

<dependency>
    <groupId>com.github.spotbugs</groupId>
    <artifactId>spotbugs-annotations</artifactId>
</dependency>

Maven Dependency Plugin

Add maven-dependency-plugin before jacoco-maven-plugin, it will copy the lombok artifact over your target/dependency folder.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>copy-dependencies</id>
      <phase>package</phase>
      <goals>
        <goal>copy-dependencies</goal>
      </goals>
      <configuration>
        <includeArtifactIds>lombok</includeArtifactIds>
      </configuration>
    </execution>
  </executions>
</plugin>

Sonar libraries

Add lombok jar file to your Sonar libraries, add the following XML tag to the properties section of your pom.xml

<sonar.java.libraries>target/dependency/*.jar</sonar.java.libraries>

Lombok configuration

Create a new lombok.config file at the root of your backend project if you didn't have one already. Otherwise use the existing lombok.config and add the following properties.

# Suppress sonar findings
lombok.extern.findbugs.addSuppressFBWarnings = true
lombok.anyConstructor.addConstructorProperties = true

Next time you scan your application, the SonarQube report should not show lombok issues or code smells.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment