SonarQube 4.4 upgrade can not show test coverage on dashboard - maven

I upgraded my sonarqube from 4.1 to 4.4. as in the latest java plugin 2.4 you don't need to have a JaCoCo plugin. I have deleted the jacoco plugin, but now i can not see Tes coverage on sonar dashboard - it's blank. We use bamboo for CI tool and run sonar build from Bamboo. we run below maven command from bamboo build .
clean verify -Psonar sonar:sonar -U -fae -Dsonar.forceAnalysis=true

With latest versions of the SQ Java plugin, tests are no longer automatically executed. They must be executed prior to the SonarQube analysis and configured so that they produce reports that can be read by the SQ Java plugin.
Everything is explained on the Code Coverage by Unit Tests for Java Project documentation page.

Related

SonarQube analysis from maven and Jenkins have different results

I am using SonarQube version 6.7 for running analysis of Maven projects using the command mvn clean verify sonar:sonar from the project directory using command prompt and get the results. The sonar configurations in settings.xml for maven (v3.5.3) are added respectively.
In Jenkins (version 2.161), I have installed SonarQube Scanner for Jenkins (v2.8.1) plugin. The SonarQube Server configuration is configured as below.
In the Jenkins maven project, I have configured the post steps as below.
I have checked the Prepare SonarQube Scanner environment in the Build Environment section and the Build goal is -e clean verify sonar:sonar.
My issue is, when the SonarQube analysis for a maven project is triggered through command prompt using the command mvn clean verify sonar:sonar, I am getting the results as expected. But when the Jenkins job is triggered with the configurations above for the same maven project, the results are different and incorrect. What am I missing?
P.S- In the Post-build Actions, I can see the SonarQube analysis with maven is deprecated.
Thanks in advance.
You use different scanners. First you used SonarScanner for Maven (mvn sonar:sonar). Next you used Basi SonarScanner, which requires manual configuration of all options.
The best option to sole it is always use the same scanner. You have Maven project, so you can enable Prepare SonarQube Scanner environment in Build Environment, and next execute Sonar goal $SONAR_MAVEN_GOAL in Build.

Uploading Spock/Groovy test results into Sonarqube

There was a known issue from 2014 that UnitTests written in Groovy cannot have their PASS/FAIL metrics uploaded into SonarQube.
http://sonarqube-archive.15.x6.nabble.com/Resource-not-found-for-Groovy-unit-tests-td5024669.html
Does anyone know if this issue is fixed? I am still have the issue with Sonar 6.1 using Spock unit tests and Gradle build system.
Any clue on the correct gradle sonar settings to make this happen?
The solution for us was to install the Groovy plugin in Sonarqube 6.1.
Once the plugin was installed, we could see the tests, with this command line:
./gradlew sonarqube -Dsonar.tests=src/test/groovy -Dsonar.junit.reportsPath=build/test-results/test/
We are using Spock as well (with Gradle, as you can see)

After upgrade to SonarQube 5.3 Cobertura test coverage is missing

I recently upgraded to SonarQube 5.3 and now test coverage using Cobertura is no longer published/analyzed.
It looks like JaCoCo is default code coverage no matter what we install or configure. Log shows that SonarQube is looking and not finding JaCoCo reports.
Is there still support for Cobertura with 5.3?
I tried to configure cobertura but sonar.java.coveragePlugin does not seem to do much anymore. You can specify what you like using this property but the JaCoCo will be used.
[INFO] JaCoCoSensor: JaCoCo report not found : E:\myproject\jacoco.exec
[INFO] JaCoCoItSensor: JaCoCo IT report not found: E:\myproject\jacoco-it.exec
Since SonarQube 4.2 the test report isn’t generated by SonarQube anymore (see SonarQube blog post for more information). So you have to do it by your own before you run the sonar analyze. For Maven builds, I wrote a sample how to integrate JaCoCo test reporting generation into a Maven build.
For Cobertura, you have to install the Cobertura Plugin for SonarQube. On that site it is explained how to generate the reports.

Jenkins jacoco plugin - Dashboard Reports are gone with Java8

Most of the projects that I'm working with used Gradle 1.6 upto 2.3 with Java7 and I'm using Jacoco for code coverage.
Jenkins version is: 1.565.3 and 1.618 (I have two instances)
Jenkins's Jacoco Plugin version: 1.0.12
Gradle version: 2.3
Gradle's Jacoco Plugin version: 0.7.2.201409121644
Now in Gradle, there's a jacoco plugin (which provides jacocoTestReport task) and in Jenkins there's a Jacoco plugin which reads the exec files generated by running various tests and shows the reports on the Jenkins job's dashboard.
These reports are not showing up now if I'm using Java 8 with Gradle 2.0 upto 2.3 versions. Jenkins jobs builds and runs the analysis on Jacoco successfully but the reports is gone.
Have you seen this issue?
If you see this, it shows Coverage is gone and with the latest build all what is there is RED / no coverage.
Main dashboard:
Jacoco Plugin report (if you click on the above report on the job):
NOTE:
I have valid .exec files which shows valid code coverage if I use Gradle's jacocoTestReport task to generate the coverage in HTML format but the Jacoco plugin dashboard reports are not showing anything (just shows the headers only with no data/no coverage at all).
Reports generated by jacocoTestReport and Jacoco plugin in Jenkins generated valid output when I'm using Java7.
Report generated by Gradle's jacocoTestReport task using the same .exec files shows that jacoco* .exec files that I have are valid.
I figured out the cause why code coverage is not showing for Java 8 projects.
It's due to the incompatible version of Jenkins's Jacoco Plugin which works only with Java7 in your Jenkins instance. Try updating Jacoco plugin in Jenkins it to the latest version (1.0.15+).
Support to Java 8 was provided with version 1.0.15. Release notes of Jacoco plugin
Version 1.0.15 (Jun 11, 2014)
• Fix [JENKINS-20440] Inspector problem
• Fix [JENKINS-22716] - Update to JaCoCo 0.7.x to support Java 8
• Fix #40 - Project Dashboard chart having data cut off
Hence, jacoco plugin needs to be upgraded in your Jenkins.
Also, see Version info/Release info here: https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin
You'd notice there's a warning message (at this time) which might be resolved in upcoming versions (in few days).
Unfortunately JaCoCo 0.7.5 breaks compatibility to previous binary formats of the jacoco.exec files, the JaCoCo plugin is currently based on JaCoCo 0.7.4, thus you cannot use this plugin with projects which already use JaCoCo 0.7.5 or newer, please stick to 0.7.4 or lower for now until the plugin is updated

Hudson build failing with NoClassDefFoundError when generating Cobertura coverage report

I'm having a problem generating a Cobertura report with Hudson and Maven, and I'm hoping that someone here may have a solution.
I can see that cobertura artifacts are generated when hudson builds my project. But when I configure my hudson project to publish the Cobertura coverage report, I see that the build fails with the following error:
Publishing Cobertura coverage report ...
Publishing Cobertura coverage results ...
FATAL: org/jfree/chart/axis/CategoryAxis
java.lang.NoClassDefFoundError: org/jfree/chart/axis/CategoryAxis
at hudson.plugins.cobertura.CoberturaXmlHandler.startDocument(...)
The build output shows that the Java version is 1.6.0_38
If I configure my project so that Cobertura coverage report is not generated, then the build succeeds.
The following plugins are installed on hudson:
Findbugs (version 4.41-h-2)
Checkstyle (version 3.28-h-1)
Cobertura (version 1-6-h-1)
Static Analysis Collector (version 1.28-h-1)
Static Analysis Utilities (version 1.42-h-1)
Maven 3 Build (version 3.0.0)
The following maven command is used:
clean install findbugs:findbugs checkstyle:checkstyle cobertura:cobertura
Any suggestions on how to fix this problem?
You need to install the JFreeChart plugin as well, it's needed for generating charts in cobertura (that's why the class not found exception while running cobertura) but it has been removed from main hudson distribution:
(JFreeChart ...) Moved to an external plugin. Available from Alpha release. Any
external plugins using JFreechart will need to add a dependency on
this external plugin to maintain compatibility. For future charting
needs BIRT Charts is now bundled as a core plugin
EDIT: there a bug in a transitive dependency as seen here.
Install cobertura-plugin version 1.6-h-3. mvn

Resources