mavensonarqubesonar-maven-plugin

sonar-maven-plugin different results


I'm using sonar-maven-plugin on my local machine (with SonarQube version: 5.6.6):

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
    <version>2.6</version>
</plugin>

And I have configured sonar on the remote build-server with jenkins:

Maven task:

$SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL clean package 

In the console output I see:

[INFO] --- sonar-maven-plugin:2.6:sonar (default-cli)
INFO: SonarQube Server 5.6.6

But i have different results (I have more bugs and Code Smells on the local machine with the same code)


Solution

  • Maven tasks are executed in the order on which they're specified on the command line, and you are executing the analysis before the build.

    SonarJava requires byte code to perform a full and complete analysis. If you're not providing class files to the analysis then you will get fewer issues that you should.

    So under the assumption that some other process wipes out some or all of the class files between analyses, this is the source of your problem. Instead, try this in your Jenkins Maven build step:

    clean package $SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL 
    

    or as separate steps

    clean package
    $SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL