Must-share information (formatted with Markdown):
- which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
- what are you trying to achieve
- what have you tried so far to achieve this
Hi
We are using Sonarqube 8.3.1 community edition in Azure Devops
We have integrated Sonarqube with Azure devops with sonar extension SonarQube - Visual Studio Marketplace
Java 11 for Sonar 8.3.1
Here we are running sonarqube for Maven project. We got the report but codecoverage is zero. SO for that we have enabled for Jacoco and also Cobertura coverage report. But not reflecting in Sonar server. We have individually tested for both plugins.
We have enabled Jacoco plugin Azure Pipeline Yaml code as below
Jacoco Code PIpeline yaml:
- task: Maven@3
timeoutInMinutes: 100
inputs:
mavenPomFile: 'cq-webapp\pom.xml'
goals: '-T 4 clean install -Puber-package -f "cq-webapp" -s "cq-webapp/settings.xml"'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
codeCoverageToolOption: 'JaCoCo'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
mavenVersionOption: 'Path'
mavenDirectory: 'C:/Softwares/apache-maven-3.6.3-bin/apache-maven-3.6.3/'
mavenSetM2Home: true
mavenOptions: '-Xmx3072m'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: true
isJacocoCoverageReportXML: true
sqMavenPluginVersionChoice: 'latest'
also find the pom.xml for Jacoco is
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
...... <!-- Some other steps --->
</properties>
### Jacoco Plugin
In Build added this
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
<outputDirectory>target/myreport</outputDirectory>
<excludes>
<exclude>*MethodAccess</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<phase>test-compile</phase>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
### ANTRUN plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
</plugin>
For Jacoco we are getting one some code coverage like 2%. and pipeline is failing with error like
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project VstsReport: An Ant BuildException has occured: Unable to read execution data file C:\azagent\A2_work\1\s\cq-webapp\CCReport43F6D5EF\jacoco.exec
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project VstsReport: An Ant BuildException has occured: Unable to read execution data file C:\azagent\A2_work\1\s\cq-webapp\CCReport43F6D5EF\jacoco.exec
[ERROR] around Ant part …… @ 8:11 in C:\azagent\A2_work\1\s\cq-webapp\target\antrun\build-main.xml: C:\azagent\A2_work\1\s\cq-webapp\CCReport43F6D5EF\jacoco.exec (The system cannot find the path specified)
###Cobertura code in pipeline
- task: Maven@3
timeoutInMinutes: 100
inputs:
mavenPomFile: 'cq-webapp\pom.xml'
goals: '-T 4 clean install -Puber-package -f "cq-webapp" -s "cq-webapp/settings.xml"'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
codeCoverageToolOption: 'Cobertura'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
mavenVersionOption: 'Default'
mavenOptions: '-Xmx3072m'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: true
sqMavenPluginVersionChoice: 'latest'
Issue is in Cobertura we are getting the report in pipeline. But not reflecting in Sonarqube server.
Cobertura Pom.xml
Properties:
<sonar.core.codeCoveragePlugin>cobertura</sonar.core.codeCoveragePlugin>
<sonar.java.coveragePlugin>cobertura</sonar.java.coveragePlugin>
<sonar.junit.reportsPath>${project.basedir}/target/surefire-reports</sonar.junit.reportsPath>
<sonar.surefire.reportsPath>${project.basedir}/target/surefire-reports</sonar.surefire.reportsPath>
<sonar.cobertura.reportPath>${project.basedir}/target/cobertura/cobertura.ser</sonar.cobertura.reportPath>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<instrumentation>
<includes>
<include>**/*.class</include>
</includes>
</instrumentation>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>clean</id>
<phase>pre-site</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<id>instrument</id>
<phase>site</phase>
<goals>
<goal>instrument</goal>
<goal>cobertura</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</execution>
</executions>
</plugin>
Please tell how to get codecoverage in sonarqube server with any of the method.