使用JaCoCo创建代码覆盖率报告时出错

时间:2015-08-18 15:46:57

标签: java maven jacoco surefire

我正在尝试使用JaCoCo为代码覆盖添加报告生成。该项目正在使用Maven,所以我有jacoco maven插件配置如下:

         <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>${jacoco.maven.plugin.version}</version>
            <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
                    </configuration>
                </execution>
                <execution>
                    <id>report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
                        <outputDirectory>${basedir}/target/jacoco</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

还有像这样的surefire插件:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven.surefire.plugin.version}</version>
            <configuration>
                <argLine>${argLine} -XX:-UseSplitVerifier</argLine>
                <printSummary>true</printSummary>
                <excludes>
                    <exclude>**/selenium/**/*.java</exclude>
                <excludes>
            </configuration>
        </plugin>

但是在运行结束时

  

mvn clean package

我收到了这样的错误:

  

[错误]无法执行目标org.jacoco:jacoco-maven-plugin:0.7.5.201505241946:关于项目LMS的报告(报告):JaCoCo测试报告生成中发生错误。创建报告时出错:文字/长度代码无效 - &gt; [帮助1]   [错误]   [错误]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。   [ERROR]使用-X开关重新运行Maven以启用完整的调试日志记录。   [错误]   [错误]有关错误和可能解决方案的更多信息,请阅读以下文章:   [错误] [帮助1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

事实是,在另一个项目中,同样的事情就像一个魅力。我在网上找不到解决方案。有人有什么想法吗?

使用-e开关我收到以下错误:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jacoco:jacoco-maven-plugin:0.7.5.201505241946:report (report) on project LMS: An error has occurred in JaCoCo Test report generation.
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: An error has occurred in JaCoCo Test report generation.
        at org.jacoco.maven.AbstractReportMojo.execute(AbstractReportMojo.java:180)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 20 more
Caused by: org.apache.maven.reporting.MavenReportException: Error while creating report: invalid literal/length code
        at org.jacoco.maven.AbstractReportMojo.executeReport(AbstractReportMojo.java:196)
        at org.jacoco.maven.AbstractReportMojo.execute(AbstractReportMojo.java:178)
        ... 22 more
Caused by: java.util.zip.ZipException: invalid literal/length code
        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
        at java.util.zip.ZipInputStream.read(ZipInputStream.java:193)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
        at org.jacoco.core.internal.ContentTypeDetector.readInt(ContentTypeDetector.java:95)
        at org.jacoco.core.internal.ContentTypeDetector.determineType(ContentTypeDetector.java:68)
        at org.jacoco.core.internal.ContentTypeDetector.<init>(ContentTypeDetector.java:63)
        at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:172)
        at org.jacoco.core.analysis.Analyzer.analyzeZip(Analyzer.java:246)
        at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:178)
        at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:208)
        at org.jacoco.maven.BundleCreator.createBundle(BundleCreator.java:78)
        at org.jacoco.maven.AbstractReportMojo.createReport(AbstractReportMojo.java:219)
        at org.jacoco.maven.AbstractReportMojo.executeReport(AbstractReportMojo.java:193)
        ... 23 more

1 个答案:

答案 0 :(得分:4)

我曾经遇到过这个问题。它似乎与Jacoco分析器无法解析某些资源(可能是git子模块或其中的zip /二进制文件)有关。简单地忽略此任务的资源文件夹的路径可以解决问题。

请参阅:https://github.com/devhub-tud/devhub/commit/c21607d753fbac1ba26e8b14d4ba84f4487620f8

和: https://github.com/devhub-tud/devhub/tree/master/src/main/resources/static