4

我有一个使用 maven(scala-maven-plugin)构建的 scala 项目(带有一些 java 文件)。我们已经为代码覆盖(jacoco-maven-plugin)插入了 jacoco,这会产生良好的 scala 代码覆盖。我们可以在 /target 的典型位置看到 html / csv 报告,并且 scala 覆盖范围很好。

但是,我们无法使用声纳获得代码覆盖率来处理 scala 文件。该插件运行并发送 java 覆盖,所以我知道它从 jacoco 输出中获取了一些东西,但是缺少 scala 覆盖。

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

任何帮助表示赞赏。

这是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>
4

1 回答 1

0

可能是针对源文件夹的 jacoco/sonar 检查。在这种情况下,您应该尝试将 scala 源文件夹公开给其他插件(通过 'add-source' 目标):

         <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>
于 2013-02-22T09:30:13.283 回答