Skip to content

Add sonar-project.properties for Java coverage on 7.4.x#1432

Open
Nitin Singh (nitsingh-ui) wants to merge 13 commits into7.4.xfrom
fix-sonarqube-coverage-for-7-4-x
Open

Add sonar-project.properties for Java coverage on 7.4.x#1432
Nitin Singh (nitsingh-ui) wants to merge 13 commits into7.4.xfrom
fix-sonarqube-coverage-for-7-4-x

Conversation

@nitsingh-ui
Copy link
Copy Markdown
Member

Summary

This PR adds sonar-project.properties to enable SonarQube coverage reporting for Java code on the 7.4.x branch.

Problem

  • SonarQube shows 0% coverage despite JaCoCo generating coverage data
  • sonar-project.properties file is missing on 7.4.x (exists on master but configured for Python)
  • JaCoCo generates coverage in utility-belt/target/site/jacoco/jacoco.xml but SonarQube doesn't know where to find it

Solution

Add sonar-project.properties configured for Java:

  • Set sonar.language=java (changed from Python on master)
  • Add sonar.coverage.jacoco.xmlReportPaths=**/target/site/jacoco/jacoco.xml
  • Add sonar.java.binaries=**/target/classes

Verification

From build logs, we confirmed:

  • ✅ Java tests run: 16 tests in utility-belt module
  • ✅ JaCoCo generates coverage: utility-belt/target/site/jacoco/jacoco.xml
  • ✅ Coverage data exists in artifacts
  • ✅ Python tests are disabled (they test Docker images, not code)

After this PR:

  • ✅ SonarQube will find and report coverage
  • ✅ Coverage metrics will appear in PRs

Testing Plan

  • Verify PR build completes successfully
  • Check SonarQube report shows coverage % (not 0%)
  • Confirm no test failures

References

  • Compared with schema-registry implementation (working reference)
  • Based on master branch file adapted for Java
  • Python tests disabled via docker.skip-test=true in io.confluent:common parent POM

This adds SonarQube configuration to enable coverage reporting for Java code.

Changes:
- Add sonar-project.properties configured for Java
- Set coverage path to JaCoCo XML reports
- Configure Java binaries path for analysis

The file was missing on 7.4.x branch, causing 0% coverage reports even
though JaCoCo is generating coverage data during builds.

Background:
- JaCoCo generates coverage: utility-belt/target/site/jacoco/jacoco.xml
- Java tests run: 16 tests in utility-belt module
- Python tests are disabled (test Docker images, not code)

This follows the pattern from schema-registry and other Java projects.

Fixes: SonarQube coverage reporting
Tested: Verified JaCoCo generates coverage in Semaphore builds
@nitsingh-ui Nitin Singh (nitsingh-ui) requested a review from a team as a code owner March 22, 2026 09:15
Nitin Singh (nitsingh-ui) and others added 12 commits March 22, 2026 14:52
Enable SonarQube for common-docker with coverage exclusions for generated files,
build artifacts, and test files to ensure accurate coverage reporting.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Python tests are disabled (docker.skip-test=true) and are Docker integration
tests, not code tests. Excluding .py files focuses coverage on Java code only.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add || true to test-results artifact push in both AMD and ARM blocks
to prevent race condition when blocks run in parallel. This ensures both
blocks continue to push their target directories even if test-results
push fails due to duplicate artifact.

Without this fix, whichever block finishes second fails on test-results
push and skips pushing its target directory, causing SonarQube to fail
with 404 artifact not found error.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Update paths to match artifact directory structure after pulling
target-AMD and target-ARM artifacts in after_pipeline SonarQube job.

Before: **/target/classes (doesn't exist after artifact pull)
After: target-AMD/**/classes,target-ARM/**/classes

This fixes the error: "No files nor directories matching '**/target/classes'"

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Match schema-registry pattern using:
- sonar.java.binaries=. (current directory)
- sonar.coverage.jacoco.xmlReportPaths=**/jacoco.xml (glob pattern)

This allows SonarQube to discover binaries and coverage reports
regardless of artifact directory structure (target-AMD/target-ARM).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Move test exclusions from sonar.exclusions to coverage.exclusions only.
This allows SonarQube to analyze test code for quality issues while
excluding tests from coverage percentage calculation.

Before: Tests completely excluded from all analysis
After: Tests analyzed for code smells/bugs, excluded from coverage only

Matches schema-registry proven pattern.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Create jacoco-aggregate-common-docker module to generate XML coverage
reports required by SonarQube. This module:
- Aggregates coverage from utility-belt (only module with Java tests)
- Generates jacoco.xml in parent target/site/jacoco/ directory
- Runs during verify phase via report-aggregate goal

Matches schema-registry pattern for multi-module coverage aggregation.

Fixes: No coverage report can be found with sonar.coverage.jacoco.xmlReportPaths

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add explicit jacoco-maven-plugin configuration to parent pom.xml with:
- prepare-agent: Attaches JaCoCo agent to test JVM
- generate-code-coverage-report: Runs report goal to generate coverage

This ensures JaCoCo generates both HTML and XML reports at module level,
which the jacoco-aggregate module can then aggregate.

Matches schema-registry parent POM pattern.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add <relativePath>../pom.xml</relativePath> to parent section to tell
Maven to use the local parent POM instead of trying to download from
remote repositories.

Fixes error: Non-resolvable parent POM for jacoco-aggregate-common-docker
and 'parent.relativePath' points at wrong local POM

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Remove jacoco-aggregate-common-docker module that was causing build
failure during ci-update-version phase. The module couldn't resolve
parent POM before it was installed in the reactor.

Use simpler approach: JaCoCo plugin in parent POM generates XML reports
directly in each module's target/site/jacoco/ directory. The report goal
generates both HTML and XML by default.

SonarQube can find reports with sonar.coverage.jacoco.xmlReportPaths=**/jacoco.xml

Fixes: Non-resolvable parent POM for jacoco-aggregate-common-docker

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…validation

Created a simple Calculator utility with 9 methods and 100% test coverage to verify SonarQube is properly detecting and reporting code coverage for new code changes.

This will help validate that:
- JaCoCo is generating coverage data correctly
- SonarQube scanner is finding the coverage reports
- PR decoration shows coverage metrics for new code

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add copyright header to both files
- Fix indentation from 4 spaces to 2 spaces to match project style
- Resolve all checkstyle errors for clean build

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant