2013-02-21 102 views
3

我有一个使用maven(scala-maven-plugin)构建的scala项目(带有一些java文件)。我们有jacoco插入代码覆盖(jacoco-maven-plugin),并生成良好的scala代码覆盖率。我们可以在/ target中的典型位置看到html/csv报告,并且scala覆盖范围都很好。Jacoco和Sonar的Maven 0%覆盖率

但是,我们无法使用声纳对代码进行覆盖,以在scala文件上工作。该插件运行并发送java覆盖,所以我知道它正在从jacoco输出中获取某些内容,但scala覆盖范围已丢失。

另外,如果我运行jacoco:检查目标作为构建的一部分,它会覆盖失败,再次仅引用java覆盖率作为总覆盖率数字。这让我相信这个问题与我配置雅可比而不是声纳的方式有关。

任何帮助表示赞赏。

这里是POM

  <plugin> 
       <groupId>net.alchim31.maven</groupId> 
       <artifactId>scala-maven-plugin</artifactId> 
       <version>3.1.3</version> 
       <configuration> 
        <args> 
         <arg>-g:vars</arg> 
        </args> 
       </configuration> 
       <executions> 
        <execution> 
         <goals> 
          <goal>compile</goal> 
          <goal>testCompile</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.jacoco</groupId> 
       <artifactId>jacoco-maven-plugin</artifactId> 
       <version>0.6.2.201302030002</version> 
       <executions> 
        <execution> 
         <id>prepare-agent</id> 
         <goals> 
          <goal>prepare-agent</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>report</id> 
         <phase>prepare-package</phase> 
         <goals> 
          <goal>report</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <!-- disable surefire --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>${maven.plugin.surefire.version}</version> 
       <configuration> 
        <skipTests>true</skipTests> 
       </configuration> 
      </plugin> 
      <!-- enable scalatest --> 
      <plugin> 
       <groupId>org.scalatest</groupId> 
       <artifactId>scalatest-maven-plugin</artifactId> 
       <version>1.0-M2</version> 
       <executions> 
        <execution> 
         <id>test</id> 
         <phase>test</phase> 
         <goals> 
          <goal>test</goal> 
         </goals> 
         <configuration> 
          <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory> 
          <junitxml>.</junitxml> 
          <parallel>true</parallel> 
          <tagsToExclude>IntegrationTest</tagsToExclude> 
          <filereports>ScalaTestSuite.txt</filereports> 
         </configuration> 
        </execution> 
        <execution> 
         <id>integration-test</id> 
         <phase>integration-test</phase> 
         <goals> 
          <goal>test</goal> 
         </goals> 
         <configuration> 
          <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory> 
          <junitxml>.</junitxml> 
          <parallel>true</parallel> 
          <tagsToInclude>IntegrationTest</tagsToInclude> 
          <filereports>ScalaIntegrationTestSuite.txt</filereports> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.sonar</groupId> 
       <artifactId>sonar-maven3-plugin</artifactId> 
       <version>3.4.1</version> 
      </plugin> 




    <sonar.host.url>http://vltapp02:9000/</sonar.host.url> 
    <sonar.jdbc.url>jdbc:h2:tcp://vltapp02:9092/sonar</sonar.jdbc.url> 
    <sonar.language>java</sonar.language> 
    <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin> 
    <sonar.jacoco.reportPath>target/jacoco.exec</sonar.jacoco.reportPath> 
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis> 
    <sonar.surefire.reportsPath>target/surefire-reports</sonar.surefire.reportsPath> 
+0

您是否曾经找到过解决方案? – RubberDuck 2017-08-07 21:12:06

+1

最后我写了https://github.com/scoverage/sbt-scoverage – monkjack 2017-08-10 23:57:25

回答

0

的相关部分可能是对源文件夹jacoco /声纳检查。在这种情况下,您应该尝试将scala源文件夹暴露给其他插件(通过“添加源”目标):

  <plugin> 
      <groupId>net.alchim31.maven</groupId> 
      <artifactId>scala-maven-plugin</artifactId> 
      <version>3.1.3</version> 
      <configuration> 
       <args> 
        <arg>-g:vars</arg> 
       </args> 
      </configuration> 
      <executions> 
       <execution> 
        <goals> 
         <goal>add-source</goal> 
         <goal>compile</goal> 
         <goal>testCompile</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
+0

感谢您的回复。不幸的是,我仍然遇到同样的问题。 [INFO] [09:57:45.824]分析C:\ development \ workspace \ mpp \ mpp-buster \ target \ jacoco.exec [警告] [09:57:45.926]未收集覆盖信息。也许你忘了将调试信息包含到编译的类中? – monkjack 2013-02-22 10:00:35

+0

@monkjack因此,在调试模式下编译,如警告通知 – Cole9350 2014-03-04 17:14:37

+0

我已经尝试过了。 – monkjack 2014-03-04 20:59:48

相关问题