What I'm trying to achieve integrates SonarQube analysis into the build process, so whenever mvn clean install is run, the code is analyzed using SonarQube. We want to use it for local analysis, as well as for creating on Jenkins. If new problems are found, then the assembly should fail (for this we want to use the break breaker plugin). Thus, the developer would know that by his code he was going to introduce new problems and would have to fix them for the assembly to work.
When I run mvn sonar:sonar , the analysis takes 30 seconds, and this is normal.
However, the problem occurs when I try to relate the sonar phases to the maven build goals. I bind the sonar phase to verify . Now the assembly takes 5 minutes , which is too large. It takes about 1 minute . The assembly itself without SonarQube analysis takes 30 seconds.
Note (may help to find out what the problem is): the project on which the assembly is performed has several modules in it, and I think this is the problem. It seems that the goal sonar:sonar is executed several times, once for each submodule, and the whole project is analyzed several times (not only submodules). So, we have 4 submodules, and the report is generated 5 times during assembly.
Instead, we want to analyze the entire project only once, not 5 times. It is also important that this analysis be performed at the end of the assembly after generating cobertura reports for all modules.
So, how do I integrate SonarQube analysis into the assembly, so that it analyzes my multi-module project only once, after all, after the coberture reports are generated for all submodules?
SonarQube plugin properties in parent pom:
<sonar.jdbc.url>jdbc:url</sonar.jdbc.url> <sonar.analysis.mode>preview</sonar.analysis.mode> <sonar.issuesReport.html.enable>true</sonar.issuesReport.html.enable> <sonar.issuesReport.console.enable>true</sonar.issuesReport.console.enable> <sonar.host.url>sonar.host:9000</sonar.host.url> <sonar.language>java</sonar.language> <sonar.buildbreaker.skip>false</sonar.buildbreaker.skip> <sonar.qualitygate>Sonar%20way%20with%20Findbugs</sonar.qualitygate> <sonar.preview.includePlugins>buildbreaker</sonar.preview.includePlugins> <sonar.exclusions>file:**/target/**</sonar.exclusions> <branch>development</branch>
Configuration of plugins in the pom project:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>cobertura</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>2.5</version> <executions> <execution> <phase>verify</phase> <goals> <goal>sonar</goal> </goals> </execution> </executions> </plugin>