You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

借助Jenkins Maven多模块应用集成JaCoCo到SonarQube遇阻求助

Troubleshooting JaCoCo Coverage Not Showing in SonarQube 6.7.2

Hey there, I’ve been in your exact situation—spending a full workday troubleshooting coverage data that just won’t show up in SonarQube when everything looks configured right. Let’s break down the most common fixes tailored to your environment (SonarQube 6.7.2, Maven 3.5.2, Windows Server 2012 R2):

1. Double-Check Your SonarQube Maven Command

Make sure you’re explicitly pointing Sonar to your JaCoCo report file when running the scan. Windows path separators can be finicky—use either forward slashes or double backslashes:

mvn clean verify sonar:sonar -Dsonar.jacoco.reportPaths=target/jacoco.exec

If you’re generating XML reports (sometimes more reliable for older Sonar versions):

mvn clean verify sonar:sonar -Dsonar.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml

2. Validate Your JaCoCo Plugin Configuration in pom.xml

Ensure the JaCoCo plugin is properly bound to the verify phase (so it generates reports before Sonar runs) and uses a version compatible with SonarQube 6.7.2 (0.8.x is a safe bet):

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.2</version>
            <executions>
                <!-- Prepares agent to collect coverage during tests -->
                <execution>
                    <id>jacoco-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <!-- Generates coverage report post-tests -->
                <execution>
                    <id>jacoco-report</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- Use a Sonar Maven plugin version compatible with SonarQube 6.7.2 -->
        <plugin>
            <groupId>org.sonarsource.scanner.maven</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>3.4.0.905</version>
        </plugin>
    </plugins>
</build>

Critical: Always run mvn clean verify before sonar:sonar (or chain them like the commands above) to ensure Sonar pulls fresh coverage data.

3. Check SonarQube Project Scope Settings

Log into your SonarQube instance, navigate to your project’s Project Settings > Analysis Scope:

  • Make sure your source code paths (e.g., src/main/java) aren’t excluded in the Exclusions section.
  • Confirm test code paths (e.g., src/test/java) are listed in Test Files Inclusion if needed.

4. Verify the JaCoCo Report Has Data First

Before blaming SonarQube, check if JaCoCo actually collected coverage:

  • Open target/site/jacoco/index.html in a browser. If this report shows 0% coverage or no data:
    • Ensure your test cases ran successfully (check target/surefire-reports for test results).
    • Make sure you didn’t skip tests with -DskipTests or -Dmaven.test.skip=true during the build.

5. Rule Out Windows-Specific Issues

Windows Server 2012 R2 can have permission or path quirks:

  • Ensure the user running Maven/Sonar has read access to the target directory and its contents.
  • Avoid spaces in your project path if possible—they can cause path resolution bugs in older Maven/Sonar versions.

Start with these steps, and you’ll likely track down the issue quickly. Let me know if any of these lead you to a solution!

内容的提问来源于stack exchange,提问作者AndreOstermeier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:26:17