1

我有以下设置:

  1. 声纳库 v5.1.2
  2. 声纳亚军 v2.4
  3. Sonarqube v1.6.3 的 Cobertura 插件
  4. Sonarqube v1.2 的 Groovy 插件

所有人都拥有最新版本。

我的项目结构如下:

ParentProject
|-sonar-project.properties
|- Grails Project A
|  |-sonar-project.properties

ParentProject 文件夹 sonar-project.properties 包含以下内容:

sonar.projectKey=ParentProject
sonar.projectName=Parent Project SONARQUBE
sonar.projectVersion=1.0

sonar.scm.url=scm:svn:https://server/svn/nv/frontend/grails/trunk
sonar.scm.provider=svn
sonar.language=grvy
sonar.core.codeCoveragePlugin=cobertura
sonar.grvy.coveragePlugin=cobertura
sonar.groovy.cobertura.reportPath=target/test-reports/cobertura/coverage.xml
sonar.cobertura.reportPath=target/test-reports/cobertura/coverage.xml
sonar.sourceEncoding=UTF-8
sonar.web.file.suffixes=gsp

sonar.modules= ProjectA

# Settings for servicemodel#
ProjectA.sonar.projectBaseDir=./ProjectA

在 ProjectA 中,我们有以下 sonar-project.properties:

sonar.modules = projectA-groovymodule, projectA-javascriptmodule, projectA-webmodule

projectA-groovymodule.sonar.projectBaseDir=.
projectA-groovymodule.sonar.language=grvy
projectA-groovymodule.sonar.sources=grails-app/services,grails-app/controllers,grails-app/domain,grails-app/taglib,src/groovy
projectA-groovymodule.sonar.tests=test/unit,test/integration
projectA-groovymodule.sonar.junit.reportsPath=target/test-reports
projectA-groovymodule.sonar.cobertura.reportPath = target/test-reports/cobertura/coverage.xml
projectA-groovymodule.sonar.groovy.cobertura.reportPath=target/test-reports/cobertura/coverage.xml
projectA-groovymodule.sonar.grvy.coveragePlugin=cobertura

projectA-javascriptmodule.sonar.projectBaseDir=.
projectA-javascriptmodule.sonar.language=js
projectA-javascriptmodule.sonar.sources=grails-app, web-app/js
projectA-javascriptmodule.sonar.exclusions=web-app/js/lib/**/*

projectA-webmodule.sonar.projectBaseDir=.
projectA-webmodule.sonar.language=web
projectA-webmodule.sonar.sources=grails-app/views

我可以确认coverage.xml 已经生成并且在此处指定的文件夹中可用。

sonar-runner 的输出如下:

D:\Build\ParentProject>sonar-runner
D:\Apps\sonar-runner-2.4
SonarQube Runner 2.4
Java 1.7.0_51 Oracle Corporation (64-bit)
Windows Server 2008 R2 6.1 amd64
INFO: Runner configuration file: D:\Apps\sonar-runner-2.4\conf\sonar-runner.properties
INFO: Project configuration file: D:\Build\ParentProject\sonar-project.properties
INFO: Default locale: "en_EN", source code encoding: "UTF-8"
INFO: Work directory: D:\Build\ParentProject\.\.sonar
INFO: SonarQube Server 5.1.2
16:05:40.180 INFO  - Load global repositories
16:05:40.644 INFO  - Load global repositories (done) | time=470ms
16:05:40.689 INFO  - Server id: 20150930161227
16:05:40.696 INFO  - User cache: d:\gebruikers\user\.sonar\cache
16:05:40.888 INFO  - Install plugins
16:05:43.829 INFO  - Install JDBC driver
16:05:44.278 INFO  - Create JDBC datasource for jdbc:jtds:sqlserver://dbserver:port/db;instance=instance;SelectMethod=Cursor
16:05:48.516 INFO  - Initializing Hibernate
16:05:56.529 INFO  - Load project repositories
16:05:57.659 INFO  - Load project repositories (done) | time=1130ms
16:05:57.822 INFO  - Load project settings
16:05:59.033 INFO  - Load technical debt model
16:05:59.085 INFO  - Apply project exclusions
16:06:01.353 INFO  - -------------  Scan projectA-groovymodule
16:06:01.360 INFO  - Load module settings
16:06:01.731 INFO  - Language is forced to grvy
16:06:01.734 INFO  - Load rules
16:06:03.153 INFO  - Base dir: D:\Build\ParentProject\ProjectA
16:06:03.156 INFO  - Working dir: D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-groovymodule
16:06:03.158 INFO  - Source paths: grails-app/services, grails-app/controllers, grails-app/domain, grails-app/taglib, src/groovy
16:06:03.159 INFO  - Test paths: test/unit, test/integration
16:06:03.160 INFO  - Source encoding: UTF-8, default locale: en_EN
16:06:03.161 INFO  - Index files
16:06:03.179 INFO  - Excluded sources:
16:06:03.181 INFO  -   web-app/js/jquery/**
16:06:03.314 INFO  - 18 files indexed
16:06:03.315 INFO  - 0 files ignored because of inclusion/exclusion patterns
16:06:03.648 INFO  - Quality profile for grvy: profile
16:06:04.398 INFO  - Sensor Lines Sensor
16:06:04.512 INFO  - Sensor Lines Sensor (done) | time=114ms
16:06:04.513 INFO  - Sensor QProfileSensor
16:06:04.522 INFO  - Sensor QProfileSensor (done) | time=9ms
16:06:04.525 INFO  - Sensor InitialOpenIssuesSensor
16:06:04.682 INFO  - Sensor InitialOpenIssuesSensor (done) | time=157ms
16:06:04.683 INFO  - Sensor ProjectLinksSensor
16:06:04.696 INFO  - Sensor ProjectLinksSensor (done) | time=13ms
16:06:04.697 INFO  - Sensor VersionEventsSensor
16:06:04.716 INFO  - Sensor VersionEventsSensor (done) | time=19ms
16:06:04.717 INFO  - Sensor CodeNarc
16:06:04.718 INFO  - Executing CodeNarc
16:06:05.580 INFO  - Loaded properties file in 67ms; 346 rules
16:06:05.641 INFO  - Loading ruleset from [file:D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-groo
vymodule\codenarc\profile.xml]
16:06:07.175 INFO  - RuleSet configuration properties file [codenarc.properties] not found.
16:06:09.625 INFO  - No custom message bundle found for [codenarc-messages]. Using default messages.
16:06:11.759 INFO  - Report file [D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-groovymodule\coden
arc\report1.xml] created.
CodeNarc completed: (p1=0; p2=2; p3=2) 4140ms
16:06:11.764 INFO  - Loaded properties file in 1ms; 346 rules
16:06:11.765 INFO  - Loading ruleset from [file:D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-groo
vymodule\codenarc\profile.xml]
16:06:11.869 INFO  - RuleSet configuration properties file [codenarc.properties] not found.
16:06:15.067 INFO  - No custom message bundle found for [codenarc-messages]. Using default messages.
16:06:17.707 INFO  - Report file [D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-groovymodule\coden
arc\report2.xml] created.
CodeNarc completed: (p1=0; p2=17; p3=13) 3298ms
16:06:17.710 INFO  - Loaded properties file in 1ms; 346 rules
16:06:17.711 INFO  - Loading ruleset from [file:D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-groo
vymodule\codenarc\profile.xml]
16:06:17.826 INFO  - RuleSet configuration properties file [codenarc.properties] not found.
16:06:17.837 INFO  - No custom message bundle found for [codenarc-messages]. Using default messages.
16:06:18.969 INFO  - Report file [D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-groovymodule\coden
arc\report3.xml] created.
CodeNarc completed: (p1=0; p2=0; p3=0) 127ms
16:06:18.972 INFO  - Loaded properties file in 1ms; 346 rules
16:06:18.973 INFO  - Loading ruleset from [file:D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-groo
vymodule\codenarc\profile.xml]
16:06:19.040 INFO  - RuleSet configuration properties file [codenarc.properties] not found.
16:06:19.167 INFO  - No custom message bundle found for [codenarc-messages]. Using default messages.
16:06:19.532 INFO  - Report file [D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-groovymodule\coden
arc\report4.xml] created.
CodeNarc completed: (p1=0; p2=0; p3=2) 195ms
16:06:19.537 INFO  - Loaded properties file in 1ms; 346 rules
16:06:19.540 INFO  - Loading ruleset from [file:D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-groo
vymodule\codenarc\profile.xml]
16:06:19.586 INFO  - RuleSet configuration properties file [codenarc.properties] not found.
16:06:19.774 INFO  - No custom message bundle found for [codenarc-messages]. Using default messages.
16:06:20.092 INFO  - Report file [D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-groovymodule\coden
arc\report5.xml] created.
CodeNarc completed: (p1=0; p2=4; p3=38) 233ms
16:06:20.765 INFO  - Sensor CodeNarc (done) | time=16048ms
16:06:20.766 INFO  - Sensor GroovySensor
16:06:21.158 INFO  - GMetrics completed: 237ms
16:06:21.203 INFO  - Sensor GroovySensor (done) | time=437ms
16:06:21.204 INFO  - Sensor Groovy CoberturaSensor
16:06:21.205 INFO  - Analyzing Cobertura report: target/test-reports/cobertura/coverage.xml
16:06:21.377 INFO  - Sensor Groovy CoberturaSensor (done) | time=173ms
16:06:21.378 INFO  - Sensor SCM Sensor
16:06:21.414 INFO  - Sensor SCM Sensor (done) | time=36ms
16:06:21.415 INFO  - Sensor GroovySurefireSensor
16:06:21.417 INFO  - parsing D:\Build\ParentProject\ProjectA\target\test-reports
16:06:21.418 INFO  - Sensor GroovySurefireSensor (done) | time=3ms
16:06:21.419 INFO  - Sensor CPD Sensor
16:06:21.420 INFO  - DefaultCpdEngine is used for grvy
16:06:21.421 INFO  - Cross-project analysis enabled
16:06:21.760 INFO  - Sensor CPD Sensor (done) | time=341ms
16:06:21.769 INFO  - No quality gate is configured.
16:06:21.853 INFO  - Compare to previous analysis (2015-10-01)
16:06:21.861 INFO  - Compare over 30 days (2015-09-01, analysis of Mon Aug 31 01:18:52 CEST 2015)
16:06:21.864 INFO  - Compare over 21 days (2015-09-10, analysis of Wed Sep 09 01:18:12 CEST 2015)
16:06:22.556 INFO  - Execute decorators...
16:06:24.684 INFO  - -------------  Scan ProjectA-javascriptmodule
16:06:24.686 INFO  - Load module settings
16:06:24.727 INFO  - Language is forced to js
16:06:24.744 INFO  - Base dir: D:\Build\ParentProject\ProjectA
16:06:24.745 INFO  - Working dir: D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-javascriptmodule
16:06:24.746 INFO  - Source paths: grails-app, web-app/js
16:06:24.747 INFO  - Source encoding: UTF-8, default locale: en_EN
16:06:24.748 INFO  - Index files
16:06:24.749 INFO  - Excluded sources:
16:06:24.750 INFO  -   web-app/js/lib/**/*
16:06:24.815 INFO  - 9 files indexed
16:06:24.816 INFO  - 3 files ignored because of inclusion/exclusion patterns
16:06:24.903 INFO  - Quality profile for js: ParentProject
16:06:24.948 INFO  - Sensor Lines Sensor
16:06:24.952 INFO  - Sensor Lines Sensor (done) | time=4ms
16:06:24.953 INFO  - Sensor QProfileSensor
16:06:24.954 INFO  - Sensor QProfileSensor (done) | time=1ms
16:06:24.954 INFO  - Sensor InitialOpenIssuesSensor
16:06:25.024 INFO  - Sensor InitialOpenIssuesSensor (done) | time=70ms
16:06:25.031 INFO  - Sensor ProjectLinksSensor
16:06:25.040 INFO  - Sensor ProjectLinksSensor (done) | time=9ms
16:06:25.043 INFO  - Sensor VersionEventsSensor
16:06:25.096 INFO  - Sensor VersionEventsSensor (done) | time=53ms
16:06:25.097 INFO  - Sensor JavaScriptSquidSensor
16:06:25.101 INFO  - 9 source files to be analyzed
16:06:26.722 INFO  - Sensor JavaScriptSquidSensor (done) | time=1625ms
16:06:26.723 INFO  - 9/9 source files have been analyzed
16:06:26.724 INFO  - Sensor SCM Sensor
16:06:26.732 INFO  - Sensor SCM Sensor (done) | time=8ms
16:06:26.733 INFO  - Sensor org.sonar.plugins.javascript.lcov.UTCoverageSensor@4d2f36b2
16:06:26.733 INFO  - Sensor org.sonar.plugins.javascript.lcov.UTCoverageSensor@4d2f36b2 (done) | time=0ms
16:06:26.734 INFO  - Sensor org.sonar.plugins.javascript.lcov.ITCoverageSensor@56b007b4
16:06:26.735 INFO  - Sensor org.sonar.plugins.javascript.lcov.ITCoverageSensor@56b007b4 (done) | time=1ms
16:06:26.735 INFO  - Sensor CPD Sensor
16:06:26.736 INFO  - DefaultCpdEngine is used for js
16:06:26.736 INFO  - Cross-project analysis enabled
16:06:27.151 INFO  - Sensor CPD Sensor (done) | time=416ms
16:06:27.153 INFO  - No quality gate is configured.
16:06:27.159 INFO  - Compare to previous analysis (2015-10-01)
16:06:27.161 INFO  - Compare over 30 days (2015-09-01, analysis of Mon Aug 31 01:18:52 CEST 2015)
16:06:27.163 INFO  - Compare over 21 days (2015-09-10, analysis of Wed Sep 09 01:18:12 CEST 2015)
16:06:27.518 INFO  - Execute decorators...
16:06:27.916 INFO  - -------------  Scan ProjectA-webmodule
16:06:27.918 INFO  - Load module settings
16:06:27.949 INFO  - Language is forced to web
16:06:27.968 INFO  - Base dir: D:\Build\ParentProject\ProjectA
16:06:27.969 INFO  - Working dir: D:\Build\ParentProject\.sonar\ParentProject_ProjectA_ProjectA-webmodule
16:06:27.970 INFO  - Source paths: grails-app/views
16:06:27.970 INFO  - Source encoding: UTF-8, default locale: en_EN
16:06:27.971 INFO  - Index files
16:06:27.972 INFO  - Excluded sources:
16:06:27.973 INFO  -   web-app/js/jquery/**
16:06:28.027 INFO  - 28 files indexed
16:06:28.028 INFO  - 0 files ignored because of inclusion/exclusion patterns
16:06:28.273 INFO  - Quality profile for web: ParentProject
16:06:28.306 INFO  - Sensor Lines Sensor
16:06:28.312 INFO  - Sensor Lines Sensor (done) | time=6ms
16:06:28.312 INFO  - Sensor QProfileSensor
16:06:28.313 INFO  - Sensor QProfileSensor (done) | time=1ms
16:06:28.314 INFO  - Sensor InitialOpenIssuesSensor
16:06:28.409 INFO  - Sensor InitialOpenIssuesSensor (done) | time=95ms
16:06:28.410 INFO  - Sensor ProjectLinksSensor
16:06:28.413 INFO  - Sensor ProjectLinksSensor (done) | time=3ms
16:06:28.414 INFO  - Sensor VersionEventsSensor
16:06:28.424 INFO  - Sensor VersionEventsSensor (done) | time=10ms
16:06:28.424 INFO  - Sensor WebSensor
16:06:28.722 INFO  - Sensor WebSensor (done) | time=298ms
16:06:28.723 INFO  - Sensor SCM Sensor
16:06:28.738 INFO  - Sensor SCM Sensor (done) | time=15ms
16:06:28.739 INFO  - Sensor CPD Sensor
16:06:28.740 INFO  - DefaultCpdEngine is used for web
16:06:28.740 INFO  - Cross-project analysis enabled
16:06:29.201 INFO  - Sensor CPD Sensor (done) | time=462ms
16:06:29.203 INFO  - No quality gate is configured.
16:06:29.207 INFO  - Compare to previous analysis (2015-10-01)
16:06:29.209 INFO  - Compare over 30 days (2015-09-01, analysis of Mon Aug 31 01:18:52 CEST 2015)
16:06:29.211 INFO  - Compare over 21 days (2015-09-10, analysis of Wed Sep 09 01:18:12 CEST 2015)
16:06:29.522 INFO  - Execute decorators...
16:06:31.389 INFO  - -------------  Scan ProjectA
16:06:31.391 INFO  - Load module settings
16:06:31.440 INFO  - Base dir: D:\Build\ParentProject\ProjectA
16:06:31.441 INFO  - Working dir: D:\Build\ParentProject\.sonar\ParentProject_ProjectA
16:06:31.442 INFO  - Source encoding: UTF-8, default locale: en_EN
16:06:31.474 INFO  - Sensor Lines Sensor
16:06:31.474 INFO  - Sensor Lines Sensor (done) | time=0ms
16:06:31.475 INFO  - Sensor InitialOpenIssuesSensor
16:06:31.513 INFO  - Sensor InitialOpenIssuesSensor (done) | time=38ms
16:06:31.514 INFO  - Sensor ProjectLinksSensor
16:06:31.517 INFO  - Sensor ProjectLinksSensor (done) | time=3ms
16:06:31.518 INFO  - Sensor VersionEventsSensor
16:06:31.528 INFO  - Sensor VersionEventsSensor (done) | time=10ms
16:06:31.529 INFO  - Sensor SCM Sensor
16:06:31.530 INFO  - Sensor SCM Sensor (done) | time=1ms
16:06:31.530 INFO  - Sensor CPD Sensor
16:06:31.531 INFO  - Sensor CPD Sensor (done) | time=1ms
16:06:31.532 INFO  - No quality gate is configured.
16:06:31.537 INFO  - Compare to previous analysis (2015-10-01)
16:06:31.538 INFO  - Compare over 30 days (2015-09-01, analysis of Mon Aug 31 01:18:52 CEST 2015)
16:06:31.540 INFO  - Compare over 21 days (2015-09-10, analysis of Wed Sep 09 01:18:12 CEST 2015)
16:06:31.808 INFO  - Execute decorators...
16:06:31.932 INFO  - -------------  Scan ParentProject SonarQube Runner
16:06:31.934 INFO  - Load module settings
16:06:31.985 INFO  - Base dir: D:\Build\ParentProject
16:06:31.986 INFO  - Working dir: D:\Build\ParentProject\.sonar
16:06:31.986 INFO  - Source encoding: UTF-8, default locale: en_EN
16:06:32.020 INFO  - Sensor Lines Sensor
16:06:32.021 INFO  - Sensor Lines Sensor (done) | time=1ms
16:06:32.021 INFO  - Sensor InitialOpenIssuesSensor
16:06:32.062 INFO  - Sensor InitialOpenIssuesSensor (done) | time=41ms
16:06:32.063 INFO  - Sensor ProjectLinksSensor
16:06:32.067 INFO  - Sensor ProjectLinksSensor (done) | time=4ms
16:06:32.067 INFO  - Sensor VersionEventsSensor
16:06:32.077 INFO  - Sensor VersionEventsSensor (done) | time=10ms
16:06:32.078 INFO  - Sensor SCM Sensor
16:06:32.078 INFO  - Sensor SCM Sensor (done) | time=0ms
16:06:32.079 INFO  - Sensor CPD Sensor
16:06:32.079 INFO  - Sensor CPD Sensor (done) | time=0ms
16:06:32.081 INFO  - No quality gate is configured.
16:06:32.086 INFO  - Compare to previous analysis (2015-10-01)
16:06:32.088 INFO  - Compare over 30 days (2015-09-01, analysis of Mon Aug 31 01:18:52 CEST 2015)
16:06:32.090 INFO  - Compare over 21 days (2015-09-10, analysis of Wed Sep 09 01:18:12 CEST 2015)
16:06:32.280 INFO  - Execute decorators...
16:06:32.437 INFO  - Store results in database
16:06:34.455 INFO  - Analysis reports generated in 269ms, dir size=85 KB
16:06:34.762 INFO  - Analysis reports compressed in 305ms, zip size=57 KB
16:06:35.137 INFO  - Analysis reports sent to server in 374ms
16:06:35.138 INFO  - ANALYSIS SUCCESSFUL, you can browse http://server/dashboard/index/ParentProject
16:06:35.139 INFO  - Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report.
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
Total time: 56.500s
Final Memory: 73M/1274M
INFO: ------------------------------------------------------------------------

没有抛出任何错误,并且根据日志,找到并读取了 cobertura 报告文件。但是,在 SonarQube 屏幕中,覆盖部分是空的。

SonarQube 5.1.2 显示空覆盖的屏幕截图

任何人都可以提供任何帮助吗?

****更新****:Coverage.xml 内容(截断):

<coverage line-rate="0.1625615763546798" branch-rate="0.034403669724770644" lines-covered="33" lines-valid="203" branches-covered="15" branches-valid="436" complexity="0.0" version="2.0.3" timestamp="1444086827204">
  <sources>
    <source>
      D:/Build/ParentProject/grails-app/services
    </source>
    <source>
      D:/Build/ParentProject/src/groovy
    </source>
    <source>
      D:/Build/ParentProject/grails-app/taglib
    </source>
    <source>
      D:/Build/ParentProject/grails-app/controllers
    </source>
  </sources>
  <packages>
    <package name="" line-rate="0.5" branch-rate="0.0" complexity="0.0">
      <classes>
        <class name="GrailsMelodyConfig" filename="GrailsMelodyConfig.groovy" line-rate="1.0" branch-rate="1.0" complexity="0.0">
          <methods>
            <method name="run" signature="()Ljava/lang/Object;" line-rate="1.0" branch-rate="1.0">
              <lines>
                <line number="24" hits="1" branch="false"/>
              </lines>
            </method>
          </methods>
          <lines>
            <line number="24" hits="1" branch="false"/>
          </lines>
        </class>
        <class name="HelpContextFilters" filename="HelpContextFilters.groovy" line-rate="1.0" branch-rate="1.0" complexity="0.0">
          <methods/>
          <lines/>
        </class>
        <class name="Filters" filename="Filters.groovy" line-rate="1.0" branch-rate="1.0" complexity="0.0">
          <methods/>
          <lines/>
        </class>
        <class name="Filters$_closure1" filename="Filters.groovy" line-rate="1.0" branch-rate="1.0" complexity="0.0">
          <methods>
            <method name="doCall" signature="(Ljava/lang/Object;)Ljava/lang/Object;" line-rate="1.0" branch-rate="1.0">
              <lines>
                <line number="5" hits="1" branch="false"/>
              </lines>
            </method>
          </methods>
          <lines>
            <line number="5" hits="1" branch="false"/>
          </lines>
        </class>
        <class name="Filters$_closure1$_closure2" filename="Filters.groovy" line-rate="1.0" branch-rate="1.0" complexity="0.0">
          <methods>
            <method name="doCall" signature="(Ljava/lang/Object;)Ljava/lang/Object;" line-rate="1.0" branch-rate="1.0">
              <lines>
                <line number="6" hits="1" branch="false"/>
              </lines>
            </method>
          </methods>
          <lines>
            <line number="6" hits="1" branch="false"/>
          </lines>
        </class>
        <class name="Filters$_closure1$_closure2$_closure3" filename="Filters.groovy" line-rate="0.0" branch-rate="0.0" complexity="0.0">
          <methods>
            <method name="doCall" signature="(Ljava/lang/Object;)Ljava/lang/Object;" line-rate="0.0" branch-rate="0.0">
              <lines>
                <line number="7" hits="0" branch="true" condition-coverage="0% (0/2)">
                  <conditions>
                    <condition number="0" type="jump" coverage="0%"/>
                  </conditions>
                </line>
                <line number="8" hits="0" branch="true" condition-coverage="0% (0/4)">
                  <conditions>
                    <condition number="0" type="jump" coverage="0%"/>
                    <condition number="1" type="jump" coverage="0%"/>
                  </conditions>
                </line>
                <line number="9" hits="0" branch="false"/>
              </lines>
            </method>
          </methods>
          <lines>
            <line number="7" hits="0" branch="true" condition-coverage="0% (0/2)">
              <conditions>
                <condition number="0" type="jump" coverage="0%"/>
              </conditions>
            </line>
            <line number="8" hits="0" branch="true" condition-coverage="0% (0/4)">
              <conditions>
                <condition number="0" type="jump" coverage="0%"/>
                <condition number="1" type="jump" coverage="0%"/>
              </conditions>
            </line>
            <line number="9" hits="0" branch="false"/>
          </lines>
        </class>
      </classes>
    </package>
    <package name="com" line-rate="0.0" branch-rate="0.0" complexity="0.0">
      <classes>
        <class name="com.CustomHtmlTagLib" filename="com/CustomHtmlTagLib.groovy" line-rate="1.0" branch-rate="1.0" complexity="0.0">
          <methods/>
          <lines/>
        </class>
        <class name="com.CustomHtmlTagLib$_closure1" filename="com/CustomHtmlTagLib.groovy" line-rate="0.0" branch-rate="0.0" complexity="0.0">
          <methods>
            <method name="doCall" signature="(Ljava/lang/Object;)Ljava/lang/Object;" line-rate="0.0" branch-rate="0.0">
              <lines>
                <line number="16" hits="0" branch="false"/>
                <line number="18" hits="0" branch="true" condition-coverage="0% (0/4)">
                  <conditions>
                    <condition number="0" type="jump" coverage="0%"/>
                    <condition number="1" type="jump" coverage="0%"/>
                  </conditions>
                </line>
                <line number="19" hits="0" branch="false"/>
                <line number="21" hits="0" branch="false"/>
              </lines>
            </method>
          </methods>
          <lines>
            <line number="16" hits="0" branch="false"/>
            <line number="18" hits="0" branch="true" condition-coverage="0% (0/4)">
              <conditions>
                <condition number="0" type="jump" coverage="0%"/>
                <condition number="1" type="jump" coverage="0%"/>
              </conditions>
            </line>
            <line number="19" hits="0" branch="false"/>
            <line number="21" hits="0" branch="false"/>
          </lines>
        </class>
        <class name="com.CustomHtmlTagLib$_closure2" filename="com/CustomHtmlTagLib.groovy" line-rate="0.0" branch-rate="1.0" complexity="0.0">
          <methods>
            <method name="doCall" signature="(Ljava/lang/Object;)Ljava/lang/Object;" line-rate="0.0" branch-rate="1.0">
              <lines>
                <line number="26" hits="0" branch="false"/>
              </lines>
            </method>
          </methods>
          <lines>
            <line number="26" hits="0" branch="false"/>
          </lines>
        </class>
      </classes>
    </package>
    ... TRUNCATED ...
  </packages>
</coverage>
4

1 回答 1

1

终于,得到了上述问题的答案。将其发布在这里,以便对其他人有所帮助。

在coverage.xml 中,对于某些源文件,行号被评估为“0”,如下所示:

<line number="0" hits="0" branch="true" condition-coverage="33% (1/3)">
  <conditions>
    <condition number="0" type="switch" coverage="33%"/>
  </conditions>
</line>

有两种解决方案来处理相同的问题:

  1. 降级用于生成coverage.xml的cobertura插件并检查coverage.xml是否仍然生成上述行

或者

  1. 在 BuildConfig.groovy 中从覆盖范围中排除文件,如下所示(因为我正在使用 Grails 应用程序):

    覆盖{排除= [“FileA*”、“FileB*”、“**/package/*”]}

更多信息:

即使他们面临 ArrayIndexOutOfBoundsException,我也尝试了他们的解决方案,它也对我有用。

更新:我还将 Sonarqube Groovy 插件从 1.2 恢复到 1.0.1,它也有助于上述解决方案。上述解决方案不适用于 Sonarqube Groovy 插件 1.2。

更新 2:我创建了一个小的 groovy 代码,它将在 coverage.xml 创建结束时和运行声纳运行器之前运行。这个 groovy 代码遍历所有创建的coverage.xml 并删除包含行号=“0”的节点。这样,文件也是覆盖范围的一部分,没有任何内容被排除在外。

于 2015-10-07T12:29:38.920 回答