I am able to integrate JaCoCo plugin and I can see the coverage report in Sonar 5.3 when I run
mvn sonar:sonar
but whereas when I run it from Jenkins it uploads the metrics to Sonar without the coverage report and displays this message
This component does not have coverage details.
Any ideas how to resolve this issue? Below is a snippet of my Sonar properties in pom.xml:
<properties>
<java.version>1.8</java.version>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.junit.reportsPath>${project.basedir}/target/surefire-reports</sonar.junit.reportsPath>
<sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
</properties>
`
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<phase>process-resources</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Related
When I run sonar my code coverage always coming 0. I am using clover. Below entry in pom.xml file
<properties>
<java.version>11</java.version>
<lombok.release>1.18.20</lombok.release>
<spring-cloud.version>Hoxton.SR11</spring-cloud.version>
<vigilphoenix-transformer-core.version>1.3-SNAPSHOT</vigilphoenix-transformer-core.version>
<clover.version>4.2.0</clover.version>
<sonar.java.coveragePlugin>clover</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.clover.reportPath>target\site\clover\clover.xml</sonar.clover.reportPath>
</properties>
<plugin>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>${clover.version}</version>
<configuration>
<includesTestSourceRoots>false</includesTestSourceRoots>
<targetPercentage>0%</targetPercentage>
<debug>true</debug>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>setup</goal>
</goals>
</execution>
<execution>
<id>aggregate</id>
<phase>test</phase>
<goals>
<goal>clover</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<configuration>
<!--cloverDatabase>${project.build.directory}/target/clover/cloverMerge.db</cloverDatabase-->
<generateHtml>false</generateHtml>
<generatePdf>false</generatePdf>
<generateXml>true</generateXml>
<generateHistorical>false</generateHistorical>
</configuration>
</plugin>
When i run "mvn clean install" my clover.xml generate in "\target\site\clover\clover.xml"
Not sure what I have to do. if any one can help would be more help full.
You either need to configure the clover plugin which by default take that path or in your call for sonar from maven you can add it manually:
mvn sonar:sonar -Dsonar.clover.reportPath=\target\site\clover\clover.xml
I'm using jacococ 0.8.7 version, maven 3.3.9 version, jDK 1.8 while I was running from Jenkins I'm facing below exception. what could be the issue? it worked when I used jacoco 0.7.4
command using in Jenkins:
-Dmaven.test.failure.ignore=true -U clean org.jacoco:jacoco-maven-plugin:0.8.7:prepare-agent org.jacoco:jacoco-maven-plugin:0.8.7:report test
Error
Execution default-cli of goal org.jacoco:jacoco-maven-plugin:0.8.7:prepare-agent failed: A required class was missing while executing org.jacoco:jacoco-maven-plugin:0.8.7:prepare-agent: org/jacoco/core/runtime/AgentOptions
pom.xml
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
I have unit test cases written using jmockit(version:1.44) library in my application. I am able to run the test cases using maven surefire plugin and generate coverage reports using below dependency-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
-javaagent:${project.basedir}/repo/org/jmockit/1.44/jmockit-1.44.jar
</argLine>
<forkMode>once</forkMode>
</configuration>
</plugin>
However, I want to integrate coverage report with sonar qube and started using jacoco plugin instead of surefire.
But I am getting the exception -
[ERROR] PwdResetControllerTest.setUp:76 NoClassDefFound mockit.MockUp
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Please help.
My pom.xml has the below properties:
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/../target/jacoco.exec</sonar.coverage.jacoco.xmlReportPaths>
<sonar.language>java</sonar.language>
<surefire.plugin.argline>-XX:PermSize=256m -XX:MaxPermSize=1048m</surefire.plugin.argline>
This is what I have in my Jacoco plugin configuration:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>target/jacoco.exec</destFile>
<propertyName>surefireArgLine</propertyName>
<append>true</append>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<outputDirectory>target/jacoco-report</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<destFile>target/jacoco.exec</destFile>
<dataFile>target/jacoco.exec</dataFile>
<append>true</append>
</configuration>
</plugin>
I'm using Sonar 7.8. I see the jacoco.exec file into the target folder after run:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar
However, when I go to the Sonar page, I see how many test I have, but I only see 0% in the test coverage. Any suggestion?
In Eclipse, I have used EcLEmma to see the unit test code coverage. Which worked fine.
Therefore I have tried to use the JaCoCo plugin for Maven to see the same report with Surefire from Maven build, or even better, with a certain profile, or in the site cycle. Without success. All suggested solutions here didn't work for me.
What is the best way to get a unit test code coverage report (with surefire)?
[Edit]
to be more specific why jacoco failed for me.... as I got always the
Skipping JaCoCo execution due to missing execution data
from the pom
in the properties
<jacoco.it.execution.data.file>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.it.execution.data.file>
<jacoco.ut.execution.data.file>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.ut.execution.data.file>
in the Build section
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<versionRange>${jacoco.version}</versionRange>
<executions>
<!-- Prepares the property pointing to the JaCoCo runtime agent
which is passed as VM argument when Maven the Surefire plugin is executed. -->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution
data. -->
<destFile>${jacoco.ut.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for
JaCoCo runtime agent. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!-- Ensures that the code coverage report for unit tests is created
after unit tests have been run. -->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution
data. -->
<dataFile>${jacoco.ut.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
<!-- Prepares the property pointing to the JaCoCo runtime agent
which is passed as VM argument when Maven the Failsafe plugin is executed. -->
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution
data. -->
<destFile>${jacoco.it.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for
JaCoCo runtime agent. -->
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<!-- Ensures that the code coverage report for integration tests
after integration tests have been run. -->
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution
data. -->
<dataFile>${jacoco.it.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</pluginExecutionFilter>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
was my last try but the pom becomes bigger and bigger without any result
which failes with
configuring report plugin org.apache.maven.plugins:maven-jxr-plugin:2.3
configuring report plugin org.jacoco:jacoco-maven-plugin:0.7.5.201505241946
Skipping JaCoCo execution due to missing execution data file:......\target\jacoco.exec
Skipping JaCoCo execution due to missing execution data file:......\target\jacoco-it.exec
.... => long project path
Thanks user3732793
Personnaly, I only needed to add this to my pom.xml
<project>
...
<dependencies>
...
</dependencies>
<build>
<plugins>
...
<!-- Code Coverage report generation -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>generate-code-coverage-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Then I am running
mvn test
and I get the HTML report under ./target/site/jacoco/*.html
As always the solution is easy after reading the documentation which provides example poms jacoco documentation.
This profile:
<profile>
<id>test</id>
<properties>
<env>test</env>
<gebEnv>test</gebEnv>
<jacoco.skip>false</jacoco.skip>
<maven.test.skip>false</maven.test.skip>
<skip.unit.tests>false</skip.unit.tests>
</properties>
</profile>
This in the build section:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
And this in the reporting section:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
</plugin>
Than this does all:
mvn clean install site -P test