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
  • 相关阅读:
    windows 将常用程序添加到右键菜单中去
    用MediaPlayer播放assets中的音乐文件出现的问题
    android开发技巧
    windows下如何安装java6.0
    ubuntu下运行windows程序wine
    ubuntu系统备份与恢复
    Mongo北京大会3月3号召开!报名抢注火爆进行中!(免费)
    《人月神话》作者Frederick P. Brooks, Jr.大师论设计原本
    HTML 5:富媒体时代的Web内容新规范
    2011年3月华章新书书讯:ASP.NET本质论、Erlang编程指南、SNS网站构建
  • 原文地址:https://www.cnblogs.com/zhangqingsh/p/2944719.html
Copyright © 2011-2022 走看看