I want to generate junit's test coverage report. So I use jacoco maven plugin:
here my pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>${java.version}</compilerVersion>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.50</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
But when I run this:
mvn clean verify
I get error:
Results :
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ mymodule1 ---
[INFO] Loading execution data file /home/alexeij/dev/projects/JavaTestMavenBOM/mymodule1/target/jacoco.exec
[INFO] Analyzed bundle 'mymodule1' with 7 classes
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mymodule1 ---
[INFO] Building jar: /home/alexeij/dev/projects/JavaTestMavenBOM/mymodule1/target/mymodule1-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.8:check (jacoco-check) @ mymodule1 ---
[INFO] Loading execution data file /home/alexeij/dev/projects/JavaTestMavenBOM/mymodule1/target/jacoco.exec
[INFO] Analyzed bundle 'mymodule1' with 7 classes
[WARNING] Rule violated for package com.gmail.alexei28.javatestmavenbom.module1.ngnms: lines covered ratio is 0.00, but expected minimum is 0.50
[WARNING] Rule violated for package com.gmail.alexei28.javatestmavenbom.module1: lines covered ratio is 0.00, but expected minimum is 0.50
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for testprojectbom 1.0-SNAPSHOT:
[INFO]
[INFO] testprojectbom ..................................... SUCCESS [ 0.090 s]
[INFO] mymodule1 .......................................... FAILURE [ 1.710 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.961 s
[INFO] Finished at: 2022-06-01T12:24:30+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.8:check (jacoco-check) on project mymodule1: Coverage checks have not been met. See log for details. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
Details:
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:check (jacoco-check) on project mymodule1: Coverage checks have not been met. See log for details. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:check (jacoco-check) on project mymodule1: Coverage checks have not been met. See log for details.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: Coverage checks have not been met. See log for details.
at org.jacoco.maven.CheckMojo.executeCheck (CheckMojo.java:194)
at org.jacoco.maven.CheckMojo.executeMojo (CheckMojo.java:169)
at org.jacoco.maven.AbstractJacocoMojo.execute (AbstractJacocoMojo.java:46)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
You output is expected.
The report is generated in folder target/site/jacoco. See the Maven Build log below.
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ mymodule1 ---
[INFO] Loading execution data file /home/alexeij/dev/projects/JavaTestMavenBOM/mymodule1/target/jacoco.exec
[INFO] Analyzed bundle 'mymodule1' with 7 classes
Check your target/site/jacoco folder and it should be similar to below:
target/site/jacoco/
├── index.html
├── io.sampadadubey.java.jacoco
│ ├── index.html
│ ├── index.source.html
│ ├── JacocoDemoApplication.html
│ └── JacocoDemoApplication.java.html
├── jacoco.csv
├── jacoco-resources
│ ├── branchfc.gif
│ ├── branchnc.gif
│ ├── branchpc.gif
│ ├── bundle.gif
│ ├── class.gif
│ ├── down.gif
│ ├── greenbar.gif
│ ├── group.gif
│ ├── method.gif
│ ├── package.gif
│ ├── prettify.css
│ ├── prettify.js
│ ├── redbar.gif
│ ├── report.css
│ ├── report.gif
│ ├── session.gif
│ ├── sort.gif
│ ├── sort.js
│ ├── source.gif
│ └── up.gif
├── jacoco-sessions.html
└── jacoco.xml
Your build is configured like this:
prepare-agent goal during initialize phase.report goal during test phase.check goal during verify phase.Your build is failing at verify phase for failing to conform to configured check. Error from the check goal is as below:
Coverage checks have not been met. See log for details.
Here are the logs which tell you the failure details.
[INFO] --- jacoco-maven-plugin:0.8.8:check (jacoco-check) @ mymodule1 ---
[INFO] Loading execution data file /home/alexeij/dev/projects/JavaTestMavenBOM/mymodule1/target/jacoco.exec
[INFO] Analyzed bundle 'mymodule1' with 7 classes
[WARNING] Rule violated for package com.gmail.alexei28.javatestmavenbom.module1.ngnms: lines covered ratio is 0.00, but expected minimum is 0.50
[WARNING] Rule violated for package com.gmail.alexei28.javatestmavenbom.module1: lines covered ratio is 0.00, but expected minimum is 0.50
To make it more easily readable.
Rule violated for package com.gmail.alexei28.javatestmavenbom.module1.ngnms: lines
covered ratio is 0.00, but expected minimum is 0.50
Rule violated for package com.gmail.alexei28.javatestmavenbom.module1: lines
covered ratio is 0.00, but expected minimum is 0.50
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With