<tfoot id='q9y4E'></tfoot>
    <legend id='q9y4E'><style id='q9y4E'><dir id='q9y4E'><q id='q9y4E'></q></dir></style></legend>

        <bdo id='q9y4E'></bdo><ul id='q9y4E'></ul>

    1. <small id='q9y4E'></small><noframes id='q9y4E'>

    2. <i id='q9y4E'><tr id='q9y4E'><dt id='q9y4E'><q id='q9y4E'><span id='q9y4E'><b id='q9y4E'><form id='q9y4E'><ins id='q9y4E'></ins><ul id='q9y4E'></ul><sub id='q9y4E'></sub></form><legend id='q9y4E'></legend><bdo id='q9y4E'><pre id='q9y4E'><center id='q9y4E'></center></pre></bdo></b><th id='q9y4E'></th></span></q></dt></tr></i><div id='q9y4E'><tfoot id='q9y4E'></tfoot><dl id='q9y4E'><fieldset id='q9y4E'></fieldset></dl></div>
    3. 当声纳分析绑定到多模块项目中的maven生命周期时,如何使SonarQube模块只分析项目一次?

      时间:2024-05-10
        <tbody id='OhSqy'></tbody>
      <i id='OhSqy'><tr id='OhSqy'><dt id='OhSqy'><q id='OhSqy'><span id='OhSqy'><b id='OhSqy'><form id='OhSqy'><ins id='OhSqy'></ins><ul id='OhSqy'></ul><sub id='OhSqy'></sub></form><legend id='OhSqy'></legend><bdo id='OhSqy'><pre id='OhSqy'><center id='OhSqy'></center></pre></bdo></b><th id='OhSqy'></th></span></q></dt></tr></i><div id='OhSqy'><tfoot id='OhSqy'></tfoot><dl id='OhSqy'><fieldset id='OhSqy'></fieldset></dl></div>
        <legend id='OhSqy'><style id='OhSqy'><dir id='OhSqy'><q id='OhSqy'></q></dir></style></legend>

          <bdo id='OhSqy'></bdo><ul id='OhSqy'></ul>
        • <tfoot id='OhSqy'></tfoot>

              1. <small id='OhSqy'></small><noframes id='OhSqy'>

                本文介绍了当声纳分析绑定到多模块项目中的maven生命周期时,如何使SonarQube模块只分析项目一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想要实现的是将 SonarQube 分析集成到构建过程中,以便每当运行 mvn clean install 时,都会使用 SonarQube 分析代码.我们希望将其用于本地分析以及基于 Jenkins 的构建.如果发现新问题,那么构建应该会失败(我们想为此使用构建中断插件).这样,开发人员就会知道他的代码将引入新问题,并且必须修复它们才能使构建工作.

                What I am trying to achieve is integrate SonarQube analysis into the build process, so that whenever mvn clean install is run, the code is analyzed with SonarQube. We want to use it for local analysis and also for build on Jenkins. If new issues are found, than the build should fail (we want to use build breaker plugin for that). This way the developer would know that by his code his is going to introduce new issues, and will have to fix them for the build to work.

                当我运行 mvn sonar:sonar 时,分析需要 30 秒,还可以.

                When I run mvn sonar:sonar, the analysis takes 30 seconds, which is OK.

                但是,当我尝试将 sonar 目标绑定到 maven 构建阶段时,就会出现问题.我将 sonar 绑定到 verify 阶段.现在构建需要 5 分钟,这太长了.大约需要 1 分钟.在没有 SonarQube 分析的情况下,构建本身需要 30 秒.

                However, the problem occurs when I am trying to bind sonar goal to maven build phases. I bind sonar to verify phase. The build takes 5 minutes now, which is too long. It should take about 1 minute. The build itself, without SonarQube analysis takes 30 seconds.

                注意(可能有助于找出问题所在):运行构建的项目中有多个模块,我想这就是问题所在.看起来 sonar:sonar 目标被执行了多次,每个子模块执行一次,并且整个项目被多次分析(不仅仅是子模块).所以,我们有 4 个子模块,在构建过程中生成了 5 次报告.

                Note (may help to figure out what the problem is): the project on which the build is run has multiple modules in it, and I guess that is the problem. It looks like sonar:sonar goal is executed multiple times, once for each submodule, and the whole project is analyzed multiple times (not only the submodules). So, we have 4 submodules, and the report is generated 5 times during the build.

                相反,我们只想分析整个项目一次,而不是 5 次.在为所有模块生成 cobertura 报告之后,在构建结束时运行此 1 分析也很重要.

                Instead, we want to analyze the whole project only once, not 5 times. It's also important for this 1 analysis to be run at the end of the build, after the cobertura reports are generated for all modules.

                那么,如何将 SonarQube 分析集成到构建中,以便它只分析我的多模块项目一次,最后在为所有子模块生成 cobertura 报告之后?

                So, how do I integrate SonarQube analysis into the build, so that it analyzes my multi-module project only once, in the end, after cobertura reports are generated for all the submodules?

                父 pom 中的 SonarQube 插件属性:

                <!-- Sonar plugin properties -->
                <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>
                

                项目pom中的插件配置:

                                <!-- Run cobertura analysis during package phase -->
                                <plugin>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>cobertura-maven-plugin</artifactId>
                                    <executions>
                                        <execution>
                                           <phase>package</phase>
                                              <goals>
                                                 <goal>cobertura</goal>
                                               </goals>
                                        </execution>
                                  </executions>
                                </plugin>
                
                                <!-- Run sonar analysis (preview mode) during verify phase. Cobertura reports need to be generated already -->
                                <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>
                

                推荐答案

                IMO,这只是一个 Maven 配置问题,您缺少 <inherited>false</inherited> 元素sonar:sonar的执行:

                IMO, this is just a Maven configuration issue, you're missing the <inherited>false</inherited> element on the execution of sonar:sonar:

                                <!-- Run sonar analysis (preview mode) during verify phase. Cobertura reports need to be generated already -->
                                <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>
                                           <inherited>false</inherited>
                                        </execution>
                                  </executions>
                                </plugin>
                

                这篇关于当声纳分析绑定到多模块项目中的maven生命周期时,如何使SonarQube模块只分析项目一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:将此 if-then-else 语句替换为单个 return 语句 下一篇:使用 SonarLint 一次分析整个项目 - 逐个文件分析会产生不完整的结果

                相关文章

                <i id='fgm26'><tr id='fgm26'><dt id='fgm26'><q id='fgm26'><span id='fgm26'><b id='fgm26'><form id='fgm26'><ins id='fgm26'></ins><ul id='fgm26'></ul><sub id='fgm26'></sub></form><legend id='fgm26'></legend><bdo id='fgm26'><pre id='fgm26'><center id='fgm26'></center></pre></bdo></b><th id='fgm26'></th></span></q></dt></tr></i><div id='fgm26'><tfoot id='fgm26'></tfoot><dl id='fgm26'><fieldset id='fgm26'></fieldset></dl></div>

                <legend id='fgm26'><style id='fgm26'><dir id='fgm26'><q id='fgm26'></q></dir></style></legend>
                1. <tfoot id='fgm26'></tfoot>
                    • <bdo id='fgm26'></bdo><ul id='fgm26'></ul>

                    <small id='fgm26'></small><noframes id='fgm26'>