This module aggregates JaCoCo coverage reports from all modules in the monorepo and sends them to SonarCloud under a single project key (pagopa_selfcare).
The coverage aggregation follows a clean separation of concerns:
-
Build & Test: All modules build and run tests independently
- Each module generates its own
jacoco.execandjacoco.xmlreports - Failures in tests cause the build to fail immediately
- Each module generates its own
-
Coverage Aggregation: After all modules succeed,
test-coveragecollects all reports- Uses JaCoCo's
report-aggregategoal - Combines all
jacoco.xmlfiles intotest-coverage/target/site/jacoco-aggregate/jacoco.xml
- Uses JaCoCo's
-
SonarCloud Upload: Coverage data is sent with a single organization key and project key
- All modules contribute to the same SonarCloud project
- Pull request analysis works across the entire monorepo
# Build and test a single module with coverage report
mvn --projects :test-coverage --also-make verify -Pdelegation-cdc,report -DskipITs
# Generates: test-coverage/target/site/jacoco-aggregate/jacoco.xml# Build all modules
mvn clean verify -DskipITs
# Then aggregate coverage reports
mvn --projects :test-coverage --also-make package -Preport -DskipTests
# Generates complete: test-coverage/target/site/jacoco-aggregate/jacoco.xmlThe GitHub Actions workflow (pr_sonar_analysis.yml) follows this pattern:
# Step 1: Build all modules and run tests
mvn clean verify -DskipITs
# Step 2: Aggregate JaCoCo reports from all modules
mvn jacoco:report-aggregate -DskipTests \
--projects :test-coverage --also-make -Preport
# Step 3: Collect all jacoco.xml paths and upload to SonarCloud
# Dynamically finds all jacoco.xml files and sends them to SonarCloud
mvn sonar:sonar --projects :root --also-make \
-Dsonar.coverage.jacoco.xmlReportPaths="<all jacoco.xml files>" \
-Dsonar.organization=pagopa \
-Dsonar.projectKey=pagopa_selfcare \
-Dsonar.token=$SONAR_TOKEN- ✅ Single SonarCloud key: All modules report to
pagopa_selfcare - ✅ Fail-fast on test failures: No
-faeflag means the build stops on first test failure - ✅ Scalable: Adding new modules automatically included in coverage reporting
- ✅ Clean separation: Build, aggregation, and analysis are separate concerns
- Ensure all modules have the JaCoCo plugin configured (inherited from
selfcare-sdk-pom) - Check that
jacoco.execfiles exist in each module'starget/directory
- Verify
test-coverage/target/site/jacoco-aggregate/jacoco.xmlexists and contains data - Check that the
-Dsonar.coverage.jacoco.xmlReportPathsin CI workflow points to correct locations
- Remove
-faeflag from Maven command - Ensure no
skipTestsorskipITsflags that bypass coverage