【问题标题】:JaCoco MVN unknown block typeJaCoco MVN 未知块类型
【发布时间】:2020-08-08 20:17:07
【问题描述】:

所以我使用 JaCoco maven 插件自动生成代码覆盖率报告,然后我可以将它们发送到 codecov 以显示在 GitHub 上。突然间,我收到 JaCoco 的构建失败,说“未知块类型”。这不是昨天发生的,所以我不知道为什么现在会发生。这是我的 pom.xml 的相关部分

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.5</version>
  <executions>
    <execution>
      <goals>
        <goal>prepare-agent</goal>
      </goals>
    </execution>
    <execution>
      <id>report</id>
      <phase>test</phase>
      <goals>
        <goal>report</goal>
      </goals>
    </execution>
  </executions>
</plugin>

如何解决此问题以正确生成覆盖率报告?

-X 轨迹

[DEBUG] Configuring mojo org.jacoco:jacoco-maven-plugin:0.8.5:report from plugin realm ClassRealm[plugin>org.jacoco:jacoco-maven-plugin:0.8.5, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@55054057]
[DEBUG] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[DEBUG] Setting property: site.resource.loader.class => 'org.codehaus.plexus.velocity.SiteResourceLoader'.
[DEBUG] Setting property: velocimacro.messages.on => 'false'.
[DEBUG] Setting property: runtime.log.invalid.references => 'false'.
[DEBUG] Setting property: resource.loader => 'classpath,site'.
[DEBUG] Setting property: velocimacro.permissions.allow.inline.to.replace.global => 'true'.
[DEBUG] Setting property: resource.manager.logwhenfound => 'false'.
[DEBUG] *******************************************************************
[DEBUG] Starting Apache Velocity v1.5 (compiled: 2007-02-22 08:52:29)
[DEBUG] RuntimeInstance initializing.
[DEBUG] Default Properties File: org/apache/velocity/runtime/defaults/velocity.properties
[DEBUG] LogSystem has been deprecated. Please use a LogChute implementation.
[DEBUG] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
[DEBUG] ResourceLoader instantiated: org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader
[DEBUG] ResourceLoader instantiated: org.codehaus.plexus.velocity.SiteResourceLoader
[DEBUG] ResourceCache: initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl)
[DEBUG] Default ResourceManager initialization complete.
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Literal
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Macro
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Parse
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Include
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
[DEBUG] Created '20' parsers.
[DEBUG] Velocimacro : initialization starting.
[DEBUG] Velocimacro : allowInline = true : VMs can be defined inline in templates
[DEBUG] Velocimacro : allowInlineToOverride = true : VMs defined inline may replace previous VM definitions
[DEBUG] Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed.
[DEBUG] Velocimacro : autoload off : VM system will not automatically reload global library macros
[DEBUG] Velocimacro : Velocimacro : initialization complete.
[DEBUG] RuntimeInstance successfully initialized.
[DEBUG] Configuring mojo 'org.jacoco:jacoco-maven-plugin:0.8.5:report' with basic configurator -->
[DEBUG]   (f) dataFile = /mnt/a/Documents/school/college/courses/csci420/UMLEditor/target/jacoco.exec
[DEBUG]   (f) outputDirectory = /mnt/a/Documents/school/college/courses/csci420/UMLEditor/target/site/jacoco
[DEBUG]   (f) outputEncoding = UTF-8
[DEBUG]   (f) project = MavenProject: UMLEditor:UMLEditor:0.0.1-SNAPSHOT @ /mnt/a/Documents/school/college/courses/csci420/UMLEditor/pom.xml
[DEBUG]   (f) skip = false
[DEBUG]   (f) sourceEncoding = UTF-8
[DEBUG]   (f) title = UMLEditor
[DEBUG] -- end configuration --
[INFO] Loading execution data file /mnt/a/Documents/school/college/courses/csci420/UMLEditor/target/jacoco.exec
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  36.600 s
[INFO] Finished at: 2020-04-25T04:24:50-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:report (report) on project UMLEditor: An error has occurred in JaCoCo report generation.: Error while creating report: Unknown block type 77. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:report (report) on project UMLEditor: An error has occurred in JaCoCo report generation.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: An error has occurred in JaCoCo report generation.
    at org.jacoco.maven.AbstractReportMojo.execute (AbstractReportMojo.java:168)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.reporting.MavenReportException: Error while creating report: Unknown block type 77.
    at org.jacoco.maven.AbstractReportMojo.executeReport (AbstractReportMojo.java:184)
    at org.jacoco.maven.AbstractReportMojo.execute (AbstractReportMojo.java:166)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.io.IOException: Unknown block type 77.
    at org.jacoco.core.data.ExecutionDataReader.readBlock (ExecutionDataReader.java:119)
    at org.jacoco.core.data.ExecutionDataReader.read (ExecutionDataReader.java:93)
    at org.jacoco.core.tools.ExecFileLoader.load (ExecFileLoader.java:60)
    at org.jacoco.core.tools.ExecFileLoader.load (ExecFileLoader.java:74)
    at org.jacoco.maven.ReportSupport.loadExecutionData (ReportSupport.java:89)
    at org.jacoco.maven.ReportMojo.loadExecutionData (ReportMojo.java:61)
    at org.jacoco.maven.AbstractReportMojo.executeReport (AbstractReportMojo.java:178)
    at org.jacoco.maven.AbstractReportMojo.execute (AbstractReportMojo.java:166)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

【问题讨论】:

  • 我不知道答案,但看看这个帖子:stackoverflow.com/questions/12269558/maven-jacoco-plugin-error
  • @AndrewCheong 刚刚尝试过,但没有运气,即使超时值非常大。我应该提到的另一件事是,即使在我遇到这个问题之前,我的 mvn 在完成最后一次测试后就挂了很长一段时间,并且似乎没有做任何事情。
  • 你可以执行你正在使用的maven命令和-X来查看更多的日志输出吗?来自 jacoco 的错误消息与它试图解析一些文件有关吗?你运行的是什么java版本?
  • 请同时发布您的错误堆栈跟踪以获取更多信息
  • @wemu 编辑了我的帖子以在测试完成后包含 -X 跟踪。项目使用java 1.8

标签: java maven jacoco jacoco-maven-plugin


【解决方案1】:

未知的方块类型

org.jacoco:jacoco-maven-plugin:0.8.5:report 执行期间表明jacoco.exec 文件已损坏。

此文件由 JaCoCo 代理在 JVM 终止时生成,并使用 JVM shutdown hook 进行测试。

文件损坏通常发生在带有测试的 JVM 被硬杀死而不是适当的优雅成功终止时。

我的 mvn 在完成最后一次测试后挂了很长一段时间,似乎什么也没做

IMO 是否确认带有测试的 JVM 没有正常终止,因为这通常表明 maven-surefire-plugin 等待您的测试终止一段时间然后杀死 JVM - 请参阅类似问题 https://github.com/jacoco/jacoco/issues/1042

总而言之,请修复您的代码/测试 - 带有测试的 JVM 应该正常终止。


我也相信我已经找到了麻烦的测试文件,因为当我排除它时,一切运行正常,甚至停止挂起。我只是不明白该文件中有什么问题会导致挂起(没有循环,唯一正在完成的“文件”是将默认的 System.out/err 流修改为单独的打印写入器),因为大多数其中一个是字符串操作。

引用http://maven.apache.org/surefire/maven-surefire-plugin/faq.htmlmaven-surefire-plugin 版本3.0.0-M4

如果您通过 System.setOut 覆盖 Java 流,情况会更糟,因为该流也应该被破坏,但 Maven 将永远不会看到测试完成并且 构建可能会挂起

【讨论】:

  • 这可能是个愚蠢的问题,但我是新手,如何确保我的测试正常终止?当我在 Eclipse 中运行它们时,我没有任何问题,并且一切都在完成后立即终止。
  • 所以我实际上已经缩小了导致问题的测试文件的范围,但我不明白是什么导致了该文件中的问题,因为我在 eclipse 中看不到问题。跨度>
  • @user13403586 首先 - 在没有 stackoverflow.com/help/minimal-reproducible-example 的情况下,有人怎么能盲目地猜测你的代码有什么问题?尽管如此,请根据您的其他 cmets 查看更新的答案。
  • 所以我已经将测试更改为不再设置 System.out,而是将 PrintWriter 传递给打印的方法,但我现在得到一个“EOFException”。我确保关闭所有流。我只是在问什么一般情况可能会导致我要注意这些情况?
  • 啊,没关系,我找到了解决方案。我有一个从 System.in 读取的扫描仪,尽管我在测试中从未使用过此扫描仪,但我确实在测试结束时关闭了扫描仪。一旦我删除了该关闭语句,它就不再挂起,问题就消失了。感谢您的所有帮助!
【解决方案2】:

我收到了非常相似的消息,执行 mvn install 产生 JaCoCo 错误(区别是 Unknown block type 45 错误而不是 Unknown block type 77 就像原来的问题一样):

[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:report (report) on project UMLEditor: An error has occurred in JaCoCo report generation.: Error while creating report: Unknown block type 45. -> [Help 1]

我通过简化执行mvn clean 并重新启动构建来消除此错误。

【讨论】:

  • 这也为我解决了这个问题。谢谢!
猜你喜欢
  • 2012-12-16
  • 2021-05-22
  • 2017-09-13
  • 2018-01-02
  • 2014-04-10
  • 2014-08-17
  • 2020-11-19
  • 1970-01-01
  • 2018-02-06
相关资源
最近更新 更多