maven jacoco: not generating code coverage report
Any particular reason why you are using an outdated version of the JaCoCo plugin? For Java 8 support, you have to use at least version 0.7.0 (see changelog).
In your configuration, the report goal is bound to the verify phase, so running mvn test
won't generate any report because it does not run the verify phase (test phase comes before verify). You have to use mvn verify
to execute tests and generate the report.
The JaCoCo project provides example Maven configurations. You can try "this POM file for a JAR project runs JUnit tests under code coverage and creates a coverage report".
Jacoco's report not generate
Since your profile is not activated by default, you need to specify -Pcoverage
to your maven command to run this profile.
mvn clean verify -Pcoverage
You can also activate your coverage
profile by adding the following to your pom.xml
<profile>
<id>coverage</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<!-- Rest of the Profile build configuration -->
</profile>
maven jacoco plugin does not generate coverage report
The setup looks ok from my point of view.
You have changed the default name of the report file. Therefore I would guess you need to tell that to the sonar analyser as well.
The jacoco default for unit tests is: ${project.build.directory}/jacoco.exec
Thats also the name sonar will try to pick up.
You can simply set a property to indicate the location for the sonar analyzer:
<properties
<sonar.jacoco.reportPath>${project.build.directory}/coverage-reports/jacoco-ut.exec</sonar.jacoco.reportPath>
...
Please verify if your jacco file exists and is non empty - if so sonar will sooner or later pick it up once the location is correctly configured.
JaCoCo Not Generating Coverage Reports based on Source File - Method names not clickable
In absence of Minimal, Complete, and Verifiable example that fully demonstrates steps to reproduce your difficulty, can only quote JaCoCo FAQ :
Why does the coverage report not show highlighted source code?
Make sure the following prerequisites are fulfilled to get source code
highlighting in JaCoCo coverage reports:
- Class files must be compiled with debug information to contain line
numbers.- Source files must be properly supplied at report generation
time.
About first point see -g
option of javac
, debug
and debuglevel
options of maven-compiler-plugin.
For the second point make sure that source file Example.java
with
package org.example;
is located in src/main/java/org/example/Example.java
Jacoco Report are not generated in the site
I was able to fix by calling plugin as below
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.argLine</propertyName>
</configuration>
</execution>
</executions>
</plugin>
Related Topics
Why Do We Have to Override the Equals() Method in Java
Keylistener, Keypressed Versus Keytyped
Abstractmethoderror Using Uribuilder on Jax-Rs
Which Concurrent Queue Implementation Should I Use in Java
Use of Java [Interfaces/Abstract Classes]
How to Handle Simultaneous Key Presses in Java
Painted Content Invisible While Resizing in Java
How to Format Localdate to String
How to Serialize a List in Java
How to Call Custom Database Functions with Hibernate
Programmatically Shut Down Spring Boot Application
How to Write a Compareto Method Which Compares Objects
How to Change My Windows Desktop Wallpaper Programmatically in Java/Groovy
How to Test If My Font Is Rendered Correctly in PDF
Cannot Create Jdbc Driver of Class ' ' for Connect Url 'Null':I Do Not Understand This Exception
Java 'Final' Method: What Does It Promise
Hibernate One-To-One: Getid() Without Fetching Entire Object