Skip to content

Quick Start Maven Plugin

badamowicz edited this page Oct 7, 2014 · 5 revisions

The Sonar-HLA Maven Plugin just wraps the API and hence provides an easy way to use Sonar-HLA from the command line or from a build job. With this example, CSV is generated and printed to console. (Remove the line breaks if you copy this example)

mvn com.github.badamowicz:sonar-hla-maven-plugin:0.4.1:extract
   -DhostUrl=http://localhost:9000
   -DprojectKeyPattern=".*sonar-hla.*"
   -DcleanValues=true
   -DsurroundFields=true
   -Dmeasures="ncloc,coverage"

This will extract all Projects matching the pattern ".*sonar-hla.*" and generate CSV from it. You will get only cleaned up values (e.g. no '%' signs will be contained) and every field in the generated CSV will be surrounded with quotation marks. For the measures, only lines of code and the coverage is extracted. The CSV is printed to console and will look like his example:

"Project";"Lines of Code";"Coverage [%]"
"com.github.badamowicz.sonar.hla:sonar-hla-parent";"600";"87.7"
"com.github.badamowicz:sonar-hla-parent";"600";"87.7"

If you want to extract all measures from all projects from a Sonar host, and Sonar is running on localhost with its default port, you may simply use all the default values from the plugin. This will melt down the command line to

mvn com.github.badamowicz:sonar-hla-maven-plugin:0.4.1:extract

If you like it even shorter, add these settings to your file $HOME/.m2/settings.xml:

  <pluginGroups>
    <pluginGroup>com.github.badamowicz</pluginGroup>
  </pluginGroups>

Then you can simply issue:

mvn sonar-hla-maven-plugin:0.4.1:extract

or

mvn sonar-hla-maven-plugin:extract

The CSV now might look like this:

Project;Lines of Code;Coverage [%];Complexity;Duplicate Lines;Issues;Blocker;Critical;Major;Minor;Info
com.github.badamowicz.sonar.hla:sonar-hla-parent;600;87.7%;102;0;27;0;0;27;0;0
com.github.badamowicz:sonar-hla-parent;600;87.7%;102;0;27;0;0;27;0;0

Maybe you may also want to refer to my homepage as well as my Blog which contains various posts about different aspects of Software Management, Continuous Integration and some related stuff.

Clone this wiki locally