Share binary between standard build and Sonar

  • SonarQube Server / DCE 2025.1
  • Jenkins 2.440 / Maven 3.5+

Hello,

I apologize if my question seems strange, but I failed to find an answer so far. I have been asked a question, for which I think I don’t know exactly what to answer, except: “it is how we’ve always been doing it”. One user asked me why they have to implement 2 calls to Maven in their pipeline, one to build their binary, and one for Sonar.

Basically, in our current pipelines, most of the time we have the following stages:

  1. build
  2. call JaCoCo and run sonar analyses
  3. wait for quality gate
  4. if quality gate is ok, push to binary repository

So the question is: would it be possible to merge #1 and #2 and just have one Maven run, or is it not recommended for some reasons — and if there are reasons not to do it, what are they?

Hi,

Yes, absolutely. Per the docs, it’s actually better to run it all in one go because:

the SonarScanner has access to the full build context and can therefore make a more thorough analysis.

Run the commands separately, and the scanner could miss important context because (per an internal thread where I was learning about this):

Maven consecutive executions are mostly stateless.

[For instance,] If you use a plugin in your build to declare additional source folders dynamically, mvn sonar:sonar won’t “see” it, because the previous plugin won’t have been executed

 
HTH,
Ann

Thank you Ann, noted :slightly_smiling_face: