zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Python3学习之路~8.5 SocketServer实现多并发
    Python3学习之路~8.4 利用socket实现文件传送+MD5校验
    [jzyzoj2021]lca模板题
    [BZOJ4542] [JZYZOJ2014][Hnoi2016] 大数(莫队+离散化)
    BZOJ3289[JZYZOJP2018]: Mato的文件管理 莫队+树状数组+离散化
    离散化的后续
    数据离散化 ( 以及 stl 中的 unique( ) 的用法 )+ bzoj3289:Mato的文件管理
    stl upper_bound()
    [BZOJ 3720][JZYZOJ 2016]gty的妹子树 强制在线 树分块/树套树
    所以学树分块的时候为什么要看vector啊sjb
  • 原文地址:https://www.cnblogs.com/zhangqingsh/p/2944719.html
Copyright © 2011-2022 走看看