首页 > 解决方案 > Maven Sonarqube Jacoco 0 覆盖

问题描述

我有一个多模块 maven 项目,当我进入 Sonarqube 时看到 0% 的覆盖率,但是当我查看 Jacoco 报告时看到正确的覆盖率{module}/target/site/index.html

这是我的 pom.xml 的相关部分

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

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>

这是我的sonar-project.properties文件

## Sonar Scanner Settings File
# SonarQube info
sonar.host.url=xxx

# Project config
sonar.language=java
sonar.projectKey=project
sonar.projectName=project
sonar.projectVersion=1.0-SNAPSHOT
sonar.github.repository=lendup/project
sonar.sources=module1/src/main/java,module2/src/main/java
sonar.tests=module1/src/test/java,module2/src/test/java
sonar.sourceEncoding=UTF-8

# Test Reports
sonar.junit.reportPaths=module1/target/surefire-reports,module2/target/surefire-reports
sonar.jacoco.reportPaths=module1/target/jacoco.exec,module2/target/jacoco.exec

## Java
sonar.java.binaries=module1/target/classes,module2/target/classes
sonar.java.source=1.8

我的项目不使用 maven surefire 插件,而是手动安装到本地 repo 中,例如

mvn install:install-file -Dfile=assets/surefire-junit4-2.17.jar -DgroupId=org.apache.maven.surefire -DartifactId=surefire-junit4 -Dversion=2.17 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true

标签: mavensonarqubejacocomaven-surefire-pluginjacoco-maven-plugin

解决方案


推荐阅读