繁体   English   中英

Jacoco SonarQube 集成

[英]Jacoco SonarQube Integration

我花了好几天试图让 SonarQube 显示来自 Maven Jacoco 插件的单元测试代码覆盖率。

我坚持的错误消息是

[INFO] Analysing .../target/jacoco.exec
[WARNING] Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?

target/site/jacoco/index.html 下的报告按预期生成,并包含行突出显示和行号。 我已经读过,如果编译的类中不包含调试信息,那么突出显示和行号将不会显示在此报告中。

我已经阅读了 Maven 默认包含调试信息,但是,以防万一我在我的项目 maven-compiler-plugin 设置中包含以下配置

<configuration>
    <debug>true</debug>
    <debuglevel>lines,vars,source</debuglevel>
</configuration>

我的 settings.xml 中有以下属性(故意省略了主机和登录名)

<properties>
    <sonar.host.url></sonar.host.url>
    <sonar.login></sonar.login>
    <sonar.ws.timeout>300</sonar.ws.timeout>
</properties>

我的 Jacoco 插件有以下配置。

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.7.201606060606</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
             <goals>
                 <goal>report</goal>
             </goals>
        </execution>
    </executions>
</plugin>

我的 jacoco.exec 位于 target/jacoco.exec 的默认位置,并且被 SonarQube 正确找到。

相关版本

Maven 3.2.2

Maven 编译器 3.5.1

Maven Surefire 2.19.1

Java 1.8.0_11

SonarQube 服务器 5.6

Jacoco Maven 插件 0.7.7.201606060606

Mac OS X 10.10.5

在此先感谢您的帮助!

- - 编辑 - -

我正在运行以下 Maven 命令

mvn clean package

mvn sonar:sonar

我在这里关注了这篇文章,它对我有用,我只更新了代码以反映最新的 JaCoCo 插件版本

    <dependency>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.9</version>
    </dependency>

并将 JaCoCo 代理添加到我的 POM 插件中:

    <build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                 <executable>true</executable>
            </configuration>
        </plugin>
        <!-- JaCoCo configuration -->
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.9</version>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

并运行以下 Maven 命令(在 Jenkins 中):

clean deploy $SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL

我有 SonarQube 6.3.0.19869、Jenkins 2.46.1、Jenkins 2.15.1 中的 Maven 集成插件(较旧的插件导致我的堆栈中出现 JVM 问题)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM