Add jacoco reports parser
What does this MR do and why?
This MR adds the Jacoco Coverage Reports Visualization
Changes:
- Adds JacocoDocument parser
- Exposes the Merge Request changed files in order to complete the full paths as jacoco only provides relative paths
- Adds boilerplate code to enable Jacoco on Gitlab's ci.yml files
By design, Jacoco needs to run and generate the report in Debug mode in order to provide line coverage.
Changes for next MRs:
- Document the feature
- Potential bug fixes
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
How to set up and validate locally
- Set up your local runners
- Create a new project using the Java/Spring project template from Gitlab
- Edit the pom.xml file and add the jacoco dependency found below
- Edit the gitlab-ci.yml and add the configuration found below
- Create a new branch and edit the source file and its' respective test file in order for them to appear in the MR Diff
- Create a new MR for the branch and let the pipeline run (You might need to retry the job a few times)
- Finally, when the Pipeline succeeds, go to your MR diff and see the highlighted marks. If the marks don't appear, try refreshing your MR page.
pom.xml
Add the following plugin to the pom.xml file
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version> <!-- use the latest version -->
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
gitlab-ci.yml
This configuration is if you're using a shell runner on a mac.
stages:
- test
- report
before_script:
# Install homebrew
- which brew || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/$USER/.zprofile
- eval "$(/opt/homebrew/bin/brew shellenv)"
# Install Maven if not installed
- which mvn || brew install maven
# Set Maven options
- 'export MAVEN_CLI_OPTS="-B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --no-transfer-progress"'
- 'export MAVEN_OPTS="-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"'
variables:
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
cache:
paths:
- .m2/repository
stages:
- test
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS clean org.jacoco:jacoco-maven-plugin:prepare-agent test jacoco:report
artifacts:
reports:
coverage_report:
coverage_format: jacoco
path: target/site/jacoco/jacoco.xml
Edited by Panos Kanellidis