How to only run unit tests once when running "maven clean install" and Sonar? How to only run unit tests once when running "maven clean install" and Sonar? jenkins jenkins

How to only run unit tests once when running "maven clean install" and Sonar?


You could just run clean install -DskipTests first and then add a second maven build step sonar:sonar.The tests (and complete sonar analysis) will be run during the build phase, and the surefire results can be collected by jenkins afterwards.


As you said, Sonar is a post compile step. Sonar requires that the build be complete and pass all of it's tests before it can run, otherwise the things it does don't make any sense.

Sonar runs the tests with instrumenting (cobertura if I remember correctly), which gives the code coverage for the tests.

So, you need to do install (or at least compile & test) before Sonar runs, and then Sonar reruns the tests with instrumenting for it's own purposes.