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
  • 相关阅读:
    [PyTorch 学习笔记] 8.1 图像分类简述与 ResNet 源码分析
    [PyTorch 学习笔记] 7.3 使用 GPU 训练模型
    [PyTorch 学习笔记] 7.2 模型 Finetune
    [PyTorch 学习笔记] 7.1 模型保存与加载
    [PyTorch 学习笔记] 6.2 Normalization
    【成都GamEver游戏公司诚邀服务器伙伴】【7~15k一年4次项目奖金】
    如何彻底隐藏iOS7应用的status bar
    更新证书错误Code Sign error: Provisioning profile ‘XXXX'can't be found
    leetcode@ [273] Integer to English Words (String & Math)
    geeksforgeeks@ Largest Number formed from an Array
  • 原文地址:https://www.cnblogs.com/zhangqingsh/p/2944719.html
Copyright © 2011-2022 走看看