What does mvn sonar:sonar do?

12,615

mvn sonar:sonar does not trigger a mvn clean install execution. It triggers a Maven Surefire plugin execution only.

This is why you need to perform a mvn clean install before each analysis - otherwise your compiled classes won't be up-to-date and therefore the Surefire execution won't include recent modifications.

Share:
12,615

Related videos on Youtube

Vinay Veluri
Author by

Vinay Veluri

Finally I am nerdier than 98% of all people. Are you a nerd? Click here to take the Nerd Test, get geeky images and jokes, and write on the nerd forum! http://www.nerdtests.com/images/ft/nq/21991e3bef.gif :-)

Updated on June 04, 2022

Comments

  • Vinay Veluri
    Vinay Veluri almost 2 years

    What are the maven lifecycle phases does the command mvn sonar:sonar execute?

    While I see the logs that run over the screen, at a very high level test, install that I spotted out.

    Consider the following example,

    I have a maven project like the following

    maven-root
    
     maven-child-1
    
     maven-child-2
    

    Consider the following scenario, I have done them sequentially at root level

    1. mvn clean install
    2. mvn sonar:sonar -- See the report
    3. Modified child-2 by adding some test cases to increase the code coverage
    4. Run mvn sonar:sonar

    My changes for the test cases are not reflecting in the report.

    1. I have deleted the report from sonarqube
    2. mvn sonar:sonar

    Still that generates me the old report.

    In brief, Do I need to perform mvn clean install and then mvn sonar:sonar ?

    If mvn sonar:sonar covers executing the mvn clean install, why the report gives me old numbers?

  • markus_
    markus_ over 3 years
    I know, your answer is years ago but I bumped in the same thing and I'm wondering: Will a mvn clean verify followed by mn sonar:sonar be sufficient? Or does it have to be an isntall?
  • Gerold Broser
    Gerold Broser almost 3 years
    @markus_ SonarQube Documentation → Analyzing Source Code → Scanners → SonarScanner for Maven mentions both and for install: „Be sure to use install as first step for multi-module projects“. However, I can't comprehend what this has to do with multi-module projects. Since SQ analyzes „• ... source code [and] • ... compiled code“ a mvn test-compile should be sufficient.
  • markus_
    markus_ almost 3 years
    Thanks for your reply, I re-read your first link to the documentation and it acutally now states, that verify in a non-multi module context is sufficient. I'm quite sure, it wasn't written that way half a year ago (-: btw.: test-compile won't be sufficient, as the upload-data step takes place later. Test execution in test will be executed as well as you may want to record and upload test coverage.
  • Wins
    Wins about 2 years
    @fabrice-sonarsource-team, I also realize that sonar:sonar also trigger Maven Failsafe plugin. Is there a way to not call it?