SonarQube recommendations


I'm currently evaluating TeamCity in order to move away from Jenkins. More or less everything is fine but I'm having problems figuring out the best way to run a SonarQube analysis.

We have Java based Maven projects.

The documentation ( states:

Triggerring the analysis with Maven is not directly supported. To use the SonarQube runner with a Maven project, add the sonar:sonar goal to your project

However, when I attempt to use maven sonar:sonar I get the following error:

Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.5:sonar (default-cli) on project library: One of setGitDir or setWorkTree must be called.

I have also tried the SonarQube runner without the Maven sonar:sonar. This runs but a number of parameters (those contained in the pom for example) aren't extracted and so the Sonar analysis is incomplete.

So, any suggestions on how to run Sonar with a Maven/Java project?


1 comment
Comment actions Permalink

To answer my own post.

In my hands the best way to add Sonar integration when you have a Maven based Java program is the following;

  • Don't use the sonar runner plugin
  • Add a build step that runs mvn sonar:sonar after a previous build step that compiles, runs tests, does code coverage analysis, etc
  • Ensure your VCS option "VCS checkout mode" is set to automatically from agent. This was the key to get over the error I posted above.
  • Also ensure clean build is checked so no old analysis files are read by the sonar analysis

that has got things working for me. Hope it's useful for someone else.



Please sign in to leave a comment.