Spring Boot SonarQube 跳过指定文件的代码覆盖率

Spring Boot SonarQube About 2,329 words

需求

对于Spring Security中的一些配置文件:HttpSecurity http等,无法覆盖代码测试。

排除检查

主要是sonar.exclusions配置,选择需要排除的.java文件,从src路径开始,以逗号隔开多个文件。

备注:sonar.exclusions排除所有检查,sonar.coverage.exclusions排除覆盖率检查。

<?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.2.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.test</groupId>
    <artifactId>hello</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>hello-world</name>
    <description>this is desc</description>
    <properties>
        <java.version>21</java.version>
        <sonar.exclusions>
            src/main/java/com/roche/miniapp/gateway/MiniAppApiGatewayApplication.java,
            src/main/java/com/roche/miniapp/gateway/security/AppJwtFilter.java,
            src/main/java/com/roche/miniapp/gateway/security/WebSecurityConfiguration.java,
            src/main/java/com/roche/miniapp/gateway/router/RouteConfiguration.java
        </sonar.exclusions>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </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>

参考

https://docs.sonarsource.com/sonarcloud/advanced-setup/analysis-scope/#restrict-the-scope-of-coverage-detection

https://stackoverflow.com/questions/70016831/exclude-files-packages-from-sonarqube-coverage

Views: 269 · Posted: 2024-04-14

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh