Skip to content

Commit

Permalink
Add jacoco for code coverage checks and reports
Browse files Browse the repository at this point in the history
  • Loading branch information
miguno committed May 7, 2024
1 parent 60bf8cf commit a65a2a9
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Features:
- Supports [Docker BuildKit](https://docs.docker.com/build/)
- Java 21 (Eclipse Temurin)
- [JUnit 5](https://github.com/junit-team/junit5) for testing,
[Jacoco](https://github.com/jacoco/jacoco) for code coverage,
[SpotBugs](https://github.com/spotbugs/spotbugs) for static code analysis
- Maven for build management, using [Maven Wrapper](https://github.com/apache/maven-wrapper)
- Supports GraalVM to create
Expand Down
17 changes: 13 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,18 @@ docker-image-run:
@echo "Running container from docker image ..."
@./start_container.sh

# clean (remove) the build artifacts
clean:
@./mvnw clean

# compile the project
compile:
@./mvnw compile

# clean (remove) the build artifacts
clean:
@./mvnw clean
# create coverage report
coverage: verify
@./mvnw jacoco:report && \
echo "Coverage report is available under {{build_dir}}/site/jacoco/"

# static code analysis via infer (requires https://github.com/facebook/infer)
infer:
Expand All @@ -83,6 +88,10 @@ format-check:
package:
@./mvnw package

# print effective pom.xml
pom:
@./mvnw help:effective-pom

# run the application locally
run:
#!/usr/bin/env bash
Expand Down Expand Up @@ -133,7 +142,7 @@ test-integration:
upgrade-mvnw:
@./mvnw wrapper:wrapper

# run all tests, plus static code analysis with spotbugs
# run all tests, plus coverage check and static code analysis
verify:
@./mvnw verify

Expand Down
103 changes: 102 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
<jacoco.version>0.8.12</jacoco.version>
<spotbugs.version>4.8.5</spotbugs.version>
<spotbugs-maven-plugin.version>4.8.5.0</spotbugs-maven-plugin.version>
<findsecbugs.version>1.12.0</findsecbugs.version> <!-- spotbugs plugin for security audits of web apps -->
Expand Down Expand Up @@ -175,6 +176,12 @@
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
</plugin>
</plugins>
</pluginManagement>

Expand All @@ -197,13 +204,20 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!--
`@{argLine}` must be included here, otherwise jacoco may
fail. You can add extra arguments after `@{argLine}`.
-->
<argLine>@{argLine}</argLine>
<!-- `forkCount` (default: 1) must not be zero for jacoco. -->
<forkCount>2</forkCount>
<skipTests>${skipUTs}</skipTests>
<systemPropertyVariables>
<!-- Make sure tests use the correct logmanager. -->
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<!--
`maven.home` is set to ensure that custom settings from
`${maven.home}/conf/settings.xml` is applied (if any).
`${maven.home}/conf/settings.xml` are applied (if any).
-->
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
Expand All @@ -214,6 +228,11 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<!--
`@{argLine}` must be included here, otherwise jacoco may
fail. You can add extra arguments after `@{argLine}`.
-->
<argLine>@{argLine}</argLine>
<skipTests>${skipTests}</skipTests>
<skipITs>${skipITs}</skipITs>
<systemPropertyVariables>
Expand Down Expand Up @@ -248,6 +267,88 @@
</executions>
</plugin>

<plugin>
<!--
Usage:
- `./mvnw jacoco:help
- `./mvnw help:describe -Dplugin=org.jacoco:jacoco-maven-plugin -Ddetail`
-->
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.basedir}/target/jacoco-unit.exec</destFile>
</configuration>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${project.basedir}/target/jacoco-integration.exec</destFile>
<append>true</append>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>merge</goal>
<goal>report</goal>
</goals>
<configuration>
<!-- merge configuration -->
<destFile>${project.basedir}/target/jacoco.exec</destFile>
<fileSets>
<fileSet>
<directory>${project.basedir}/target/</directory>
<includes>
<include>jacoco-*.exec</include>
</includes>
</fileSet>
</fileSets>
<!-- report configuration -->
<dataFile>${project.basedir}/target/jacoco.exec</dataFile>
</configuration>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
<configuration>
<dataFile>${project.basedir}/target/jacoco.exec</dataFile>
</configuration>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.60</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
Expand Down

0 comments on commit a65a2a9

Please sign in to comment.