Dienstag, 12. Juli 2016

SonarQube for Maven

If you have a SonarQube server running somewhere in the network you can check any maven project on it.
All you have to configure is the SonarQube plugin group and the SonarQube connection parameters in your maven settings.xml


<settings>
    ...
    <pluginGroups>
        <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups>
    ...
    <profiles>
        <profile>
            <id>psipenta-nexus-pjf-suite</id>
            ...
            <properties>
                <sonar.host.url>
                  http://localhost:9000
                </sonar.host.url>
                <sonar.jdbc.url>
                    jdbc:mysql://localhost:3306/sonar?useUnicode=true
                </sonar.jdbc.url>
                <sonar.jdbc.username>
                    sonar
                </sonar.jdbc.username>
                <sonar.jdbc.password>
                    sonar
                </sonar.jdbc.password>
            </properties>
        </profile>
    </profiles>
</settings>
 
Be sure that the profile, you configure the connection properties for, is the active maven profile.

Having done this, a maven project can be checked on SonarQube with

mvn sonar:sonar
 
This goal is being executed after mvn verify. This means, the project is also built and installed with this command.

As a result, you see your project at the SonarQube dashboard: http://localhost:9000/

Hint: The SonarQube project name is the project artifact name by default. It is possible to configure that name via maven:

mvn sonar:sonar -Dsonar.projectName=MY_PROJECT_ON_SONAR


Further Information

http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven
http://docs.sonarqube.org/display/SONAR/Analysis+Parameters
http://stackoverflow.com/questions/38330295/cant-sort-a-cyclic-graph-exception-running-sonar-with-eclipse-rcp-application