【问题标题】:Groovy 2.5.6 compatibility with jdk 1.7Groovy 2.5.6 与 jdk 1.7 的兼容性
【发布时间】:2019-04-27 01:34:00
【问题描述】:

无法在 jdk1.7 上运行编译 Groovy(2.5.6)/Spock 类

如果这个问题已经得到解答或者这是一个微不足道的问题,我提前道歉。

我使用的是 Groovy 2.5.6,根据 Groovy 网站,它支持从 1.6 到 1.8 的 JDK。在我使用 JDK 1.7 构建 maven 期间,Java 和 Groovy 类都被编译并且 jar 被正确构建。

当 maven-surefire-plugin 出现时,问题就开始出现了。它尝试执行 Spock 测试,这时我遇到了令人讨厌的错误 Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M1:test failed: java.lang.UnsupportedClassVersionError: com/domain/billing/asf/biz/adjustmentmodify/AdjustmentModifyActivitySpec : Unsupported major.minor version 52.0 ->

我几乎整天都在试图解决这个问题,但没有运气。如果有人知道修复,请分享。不幸的是,我被 Java 1.7 困住了。我依赖于 Groovy 应该与这个 JDK 兼容这一事实。

【问题讨论】:

  • 如果您使用 GMavenPlus,可能需要配置targetBytecode 参数。
  • 类 com/domain/billing/asf/biz/adjustmentmodify/AdjustmentModifyActivitySpec 是用 JDK8 编译的,因此不能被 7 加载。没有设置你很难猜到,为什么会这样案子)。很可能您使用 8 构建,现在也使用 7 运行测试?

标签: java groovy maven-surefire-plugin


【解决方案1】:

Groovy 2.x 与 JDK17 不兼容。 Groovy 3.0.x 开始兼容 JDK16。您必须使用 Groovy 3.0.8 (http://groovy-lang.org/changelogs/changelog-3.0.8.html) 并将 Spock 迁移到 2.0

更新:我读的是 JDK17 而不是 JDK7 :facepalm:

【讨论】:

  • 没关系,我一直在寻找 Groovy 2.5.6 是否支持 JDK17,所以这个答案至少对我有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-20
  • 1970-01-01
  • 1970-01-01
  • 2011-03-04
  • 1970-01-01
  • 2013-01-28
相关资源
最近更新 更多