scala - Maven with Jacoco 和 Sonar 0% 覆盖率

标签 scala maven sonarqube scalatest jacoco

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

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

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

任何帮助表示赞赏。

下面是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>

最佳答案

可能是针对源文件夹的 jacoco/sonar 检查。在这种情况下,您应该尝试将 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>

关于scala - Maven with Jacoco 和 Sonar 0% 覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15010284/

相关文章:

java - 比较 Scala 和 Java Double.NaN

scala - 是否有键盘快捷键来回跳到SublimeSBT控制台和sublime中的编辑器?

c++ - 我可以在哪里获得在 Linux 上对 C++ 代码运行 Sonar 库代码分析的步骤

Scala 依赖类型无法编译

maven - 通过命令行选项将子模块排除在 Maven 中执行

java - Spring应用程序上下文配置: class not found exception

maven - 无法在启用 LDAP 的情况下使用加密密码部署 Artifact

带有@Inject注解的Java方法: False-positive for the rule "Unused "private"methods should be removed"?

python - 适用于 python 的 Sonar 库 : Test success score not being discovered - The resource for 'tests.test_transformation_helper.TestCase' is not found

scala - 在Spark中读取压缩的xml文件