Sonar 不选择 lombok 注释(删除未使用的私有字段)

问题描述 投票:0回答:2

我使用的是声纳版本8.9.6。 我知道这个问题已经被问过很多次了,我已经尝试了很多,但没有一个解决方案对我有用。

以下是我尝试过的一些事情。

1)

<sonar.exclusions>
        // my domain package here
        </sonar.exclusions>
  1. 添加了以下插件

               <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.java.libraries>target/dependency/*.jar</sonar.java.libraries>
  1. 添加了 lombok.config 并添加了以下属性

    config.stopBubbling = true lombok.addLombokGenerateAnnotation = true

这些对我来说都不起作用,尤其是声纳排除根本不起作用。 如有任何帮助,我们将不胜感激,并提前致谢。

java spring spring-boot sonarqube lombok
2个回答
0
投票
Please try to add the following dependency into your pom.xml file
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

and Download lombok.jar from the given link
https://projectlombok.org/download

Now if it is zipped unzip it first and then copy it to the directory 
where you have your SpringToolSuits(STS installed).

Let say your STS version is 4.11.0.RELEASE then copy lombok.jar to STS 
directory/sts-4.11.0.RELEASE   i.e. inside STS/sts-4.11.0.RELEASE/

Now try to rebuild and update your project.

0
投票

对于这个问题,我有一个小技巧。我使用了 swagger 的 Schema 注释,问题就这样过去了。

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AccessLog {
    @Schema(description = "User ID")
    private String userId;

    @Schema(description = "Action Code")
    private String actionCode;

    @Schema(description = "User Agent")
    private String userAgent;
}
© www.soinside.com 2019 - 2024. All rights reserved.