What does mvn sonar:sonar do?
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.
Related videos on Youtube
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, 2022Comments
-
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
mvn clean install
mvn sonar:sonar
-- See the report- Modified child-2 by adding some test cases to increase the code coverage
- Run
mvn sonar:sonar
My changes for the test cases are not reflecting in the report.
- I have deleted the report from sonarqube
mvn sonar:sonar
Still that generates me the old report.
In brief, Do I need to perform
mvn clean install
and thenmvn sonar:sonar
?If
mvn sonar:sonar
covers executing themvn clean install
, why the report gives me old numbers?-
dm78 over 10 years
-
Vinay Veluri over 10 yearsThanks @DavidMays, it says "If possible, an install goal should be performed prior to the sonar:sonar one". I didn't understand what if not possible... any idea..
-
Gaurav over 5 years@dm78 link not working
-
Gerold Broser almost 3 years@Gaurav The doc is now at SonarQube Documentation → Analyzing Source Code → Scanners → SonarScanner for Maven. The source is at github.com/SonarSource/sonar-scanner-maven.
-
markus_ over 3 yearsI know, your answer is years ago but I bumped in the same thing and I'm wondering: Will a
mvn clean verify
followed bymn sonar:sonar
be sufficient? Or does it have to be anisntall
? -
Gerold Broser almost 3 years@markus_ SonarQube Documentation → Analyzing Source Code → Scanners → SonarScanner for Maven mentions both and for
install
: „Be sure to useinstall
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“ amvn test-compile
should be sufficient. -
markus_ almost 3 yearsThanks 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 intest
will be executed as well as you may want to record and upload test coverage. -
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?