2013-02-21 108 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

相關問題