Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SonarQube-Jacoco离线检测显示Maven多模块项目覆盖率为0%_Maven_Sonarqube_Jacoco Maven Plugin - Fatal编程技术网

SonarQube-Jacoco离线检测显示Maven多模块项目覆盖率为0%

SonarQube-Jacoco离线检测显示Maven多模块项目覆盖率为0%,maven,sonarqube,jacoco-maven-plugin,Maven,Sonarqube,Jacoco Maven Plugin,我正在使用jacoo脱机工具,就像我在测试用例中使用PowerMockito一样。我的是Maven多模块项目。 我使用的是PowerMockito 1.65 我的SonarQube版本是6.7 JaCoCo在每个模块中生成HTML文件,但在SonarQube中显示为0% 我的父母pom.xml <properties> <sonar.version>6.7</sonar.version> <sonar-java.version>4.

我正在使用jacoo脱机工具,就像我在测试用例中使用PowerMockito一样。我的是Maven多模块项目。 我使用的是PowerMockito 1.65 我的SonarQube版本是6.7

JaCoCo在每个模块中生成HTML文件,但在SonarQube中显示为0%

我的父母pom.xml

<properties>
    <sonar.version>6.7</sonar.version>
    <sonar-java.version>4.2</sonar-java.version>
    <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
</properties>

<dependencies>
    <dependency>
        <groupId>org.sonarsource.sonarqube</groupId>
        <artifactId>sonar-plugin-api</artifactId>
        <version>${sonar.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.sonarsource.java</groupId>
        <artifactId>sonar-java-plugin</artifactId>
        <version>5.0.1.12818</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jacoco</groupId>
        <artifactId>org.jacoco.agent</artifactId>
        <classifier>runtime</classifier>

        <version>0.7.9</version>
    </dependency>

    <dependency>
        <groupId>org.sonarsource.java</groupId>
        <artifactId>sonar-jacoco-listeners</artifactId>
        <version>4.9.0.9858</version>
        <scope>test</scope>
    </dependency>

</dependencies>

<build>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <systemPropertyVariables>
                    <jacoco-agent.destfile>${project.build.directory}/coverage.exec</jacoco-agent.destfile>
                </systemPropertyVariables>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.sonarsource.scanner.maven</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>2.6.1</version>
        </plugin>

    </plugins>
</build>
<profiles>
    <profile>
        <id>sonar-coverage</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>

            <plugins>


                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <configuration>
                        <append>true</append>
                    </configuration>
                    <executions>
                        <execution>
                            <id>default-instrument</id>
                            <goals>
                                <goal>instrument</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-restore-instrumented-classes</id>

                            <goals>
                                <goal>restore-instrumented-classes</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-report</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>report</goal>

                            </goals>
                            <configuration>
                                <dataFile>${project.build.directory}/coverage.exec</dataFile>
                            </configuration>
                        </execution>

                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
<modules>
    <module>module1</module>
    <module>module2</module>
</modules>

6.7
4.2
杰科科
org.sonarsource.sonarqube

声纳库贝报告

如果更改覆盖范围文件的默认文件位置,则覆盖范围文件的默认位置为:

您还需要告诉sonar插件在哪里可以找到它。 Sonar使用了很多,jacoco报告文件应该是:
Sonar.jacoco.reportpath
一旦sonar插件找到正确的位置,它就会工作。注:计算覆盖率声纳使用覆盖率文件和编译的类

请注意:执行
mvn clean install test sonar:sonar
,这有点多余,因为测试是安装之前的一个阶段,安装也会这样做。看见但这在这里并不重要

${project.build.directory}/jacoco.exec