Home

Awesome

SonarQube plugin for Groovy

Build status

Build Status

Description

The plugin enables analysis of Groovy within SonarQube.

It leverages CodeNarc to raise issues against coding rules, GMetrics for cyclomatic complexity and Cobertura or JaCoCo for code coverage.

Plugin0.10.20.30.40.50.61.01.11.1.11.21.31.3.11.4
CodeNarc0.90.90.130.150.16.10.170.200.230.230.240.24.10.24.10.25.2
GMetrics0.20.20.30.30.40.50.60.60.70.70.70.70.7

Steps to Analyze a Groovy Project

  1. Install SonarQube Server
  2. Install SonarQube Scanner and be sure you can call sonar-scanner from the directory where you have your source code
  3. Install the Groovy Plugin.
  4. Create a sonar-project.properties file at the root of your project
  5. Run sonar-scanner command from the project root dir
  6. Follow the link provided at the end of the analysis to browse your project's quality in SonarQube UI

Notes

CodeNarc It is possible to reuse a previously generated report from CodeNarc by setting the sonar.groovy.codenarc.reportPaths property.

Groovy File Suffixes It is possible to define multiple groovy file suffixes to be recognized by setting the sonar.groovy.file.suffixes property. Note that by default, only files having .groovy as extension will be analyzed.

Unit Tests Execution Reports Import unit tests execution reports (JUnit XML format) by setting the sonar.junit.reportsPath property. Default location is target/surefire-reports.

JaCoCo and Binaries The groovy plugin requires access to source binaries when analyzing JaCoCo reports. Consequently, property sonar.groovy.binaries has to be configured for the analysis (comma-separated paths to binary folders). For Maven and gradle projects, the property is automatically set.

Coverage Results Import

The Groovy Plugin does not generate its own test coverage report, but re-uses the ones generated by Cobertura or JaCoCo.

Code Coverage with Cobertura

To display code coverage data:

  1. Prior to the SonarQube analysis, execute your unit tests and generate the Cobertura XML report.
  2. Import this report while running the SonarQube analysis by setting the sonar.groovy.cobertura.reportPath property to the path to the Cobertura XML report. The path may be absolute or relative to the project base directory.

Code Coverage with JaCoCo

To display code coverage data:

  1. Prior to the SonarQube analysis, execute your tests and generate the JaCoCo exec file(s).
  2. In order to be able to read the exec report file, and as JaCoCo bases its analysis on binaries, set the sonar.binaries property.
  3. Set the sonar.groovy.jacoco.reportPath property to the path to the JaCoCo exec file related to your unit tests.
  4. (Optional) If you are running integration tests on top of your unit tests, you may want to set the sonar.groovy.jacoco.itReportPath to the path to JaCoCo exec file related to the integration tests.
  5. Run the SonarQube analysis.