2

When I using the follow structure on our Maven project:

<plugins>
        <plugin>
            <groupId>org.scala-tools</groupId>
            <artifactId>maven-scala-plugin</artifactId>
            <version>2.15.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <args>
                    <arg>-g:line</arg>
                </args>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.5.8.201207111220</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

The tests are executed but the jacoco.exec file is not created. I tried to add this tag destFile to prepare-agent goal but have not success (the file with coverage information is not created).

Anyone have any form to calculate code coverage of unit test for Scala using maven and Jacoco?

4

1 回答 1

1

Jacoco maven 插件的工作依赖于 JDK、Scala 和插件本身的版本。

刚刚添加了相同的配置并且它工作正常:带有报告的 jacoco.exec 和 site/jacoco 都在目标目录中:https ://github.com/plokhotnyuk/calculator/commit/e3a84db02dd942b0df71d4fa337df29512e213f6

然后在使用最新(0.6.2.201302030002)版本的 Jacoco maven 插件时代理失败:

Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
    at org.jacoco.agent.rt.internal_5d10cad.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
    at org.jacoco.agent.rt.internal_5d10cad.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:99)
    at org.jacoco.agent.rt.internal_5d10cad.PreMain.createRuntime(PreMain.java:51)
    at org.jacoco.agent.rt.internal_5d10cad.PreMain.premain(PreMain.java:43)
    ... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
    at java.lang.Class.getField(Class.java:1542)
    at org.jacoco.agent.rt.internal_5d10cad.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:136)
    ... 9 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main" 

然后通过从JDK8切换到JDK7解决了故障。覆盖率报告数字没有改变。

同样在切换到 Scala 2.10 后,源代码行高亮开始看起来不同:

斯卡拉 2.9 在此处输入图像描述

斯卡拉 2.10 在此处输入图像描述

于 2013-03-27T12:15:15.477 回答