• Maven + Sonar + Jacoco扫描代码覆盖率


    I've recently setup and successfully got Sonar and Jacoco running together. Since I'm recent with the topic, I figured I'd check on stackoverflow for similar issues and help out. I am getting results from Jacoco, but found you had to explicitly set the following parameters in addition to the properties you've listed in your post:

    sonar.core.codeCoveragePlugin=jacoco
    sonar.jacoco.reportPath=tests/jacoco-exec/jacoco.exec
    sonar.dynamicAnalysis=reuseReports
    sonar.surefire.reportsPath=tests/test-reports
    

    You have to set sonar.core.codeCoveragePlugin=jacoco if you want to be able to use the sonar.jacoco.reportPath property. Otherwise, you will have to use the sonar.jacoco.itReportPath property. However, I recommend just setting the codeCoveragePlugin and reportPath properties. Otherwise, it won't display under the default coverage widget in sonar. Please make note, you cannot use the default coverage tool and jacoco together. It has to be one or the other. I decided to use Jacoco.

    Your ant target must be configured to generate the jacoco.exec results prior to running the sonar tasks:

    <jacoco:coverage enabled="${tests.code.coverage}" destfile="${jacoco.exec.dest}">
      <junit fork="yes" printsummary="withOutAndErr" dir="${tests.working.dir}">
      ...
    

    Be sure to tell sonar to reuse reports and any sunfire reports if you're running junit before sonar, that is if you're running junit outside of sonar:

    sonar.dynamicAnalysis=reuseReports
    sonar.jacoco.reportPath=tests/jacoco-exec/jacoco.exec
    sonar.surefire.reportsPath=tests/test-reports
    

    For whatever reason, if you need more verbose debugging, use the following property:

    sonar.verbose=true


    Step1 配置settings.xml,加入profile:

    <settings>
        <profiles>
            <profile>
                <id>sonar</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
                    <!-- EXAMPLE FOR MYSQL -->
                    <sonar.jdbc.url>
                      jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8
                    </sonar.jdbc.url>
                    <sonar.jdbc.driverClassName>com.mysql.jdbc.Driver</sonar.jdbc.driverClassName>
                    <sonar.jdbc.username>sonar</sonar.jdbc.username>
                    <sonar.jdbc.password>sonar</sonar.jdbc.password>
     
                    <!-- optional URL to server. Default value is http://localhost:9000 -->
                    <sonar.host.url>
                      http://myserver:9000
                    </sonar.host.url>
                </properties>
            </profile>
         </profiles>
    </settings>
     
    Step2. 运行Maven命令:
    mvn clean install sonar:sonar -Dmaven.test.failure.ignore=true -Dsonar.branch=@FP-Dev -Dsonar.core.codeCoveragePlugin=jacoco -Dsonar.jacoco.reportPath=tests/jacoco-exec/jacoco.exec -Dsonar.dynamicAnalysis=reuseReports -Dsonar.surefire.reportsPath=tests/test-reports > log.log
  • 相关阅读:
    css3新特性总结
    ES6常用特性总览
    前端第一次面试
    将一个行数在主线程执行的4中方法
    判断邮箱格式和图片压缩
    上传图片的实现
    导航右侧添加按钮、隐藏导航条和状态栏
    从相册选取图片展示并实现自定义事件
    cell添加选中时的背景图片、显示图片和图片自适应框的大小
    设置键盘无色和状态栏风火轮、屏幕截图
  • 原文地址:https://www.cnblogs.com/zhangqingsh/p/2944719.html
Copyright © 2020-2023  润新知