Unsupported major.minor version原因一种及解决

问题

在一个遗留的Java web 项目中 (jdk7+spring4) 引入了Mockito

        
            org.mockito
            mockito-core
            3.3.3
            test
        

但是运行单元测试的时候就报错

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/mockito/junit/MockitoJUnitRunner : Unsupported major.minor version 52.0

idea中所有地方都配置的是jdk7 怎么会有这个错呢

原因

rebuild项目的时候 发现了如下的Warning信息

Warning:java: /Users/zhugw/.m2/repository/org/mockito/mockito-core/3.3.3/mockito-core-3.3.3.jar!/org/mockito/Answers.class: major version 52 is newer than 51, the highest major version supported by this compiler.
  It is recommended that the compiler be upgraded.

原来Mockito-core-3.3.3.jar本身就是由jdk8编译的

➜  .m2 javap -v -cp .//repository/org/mockito/mockito-core/3.3.3/mockito-core-3.3.3.jar org/mockito/Answers
Classfile jar:file:/Users/zhugw/.m2/repository/org/mockito/mockito-core/3.3.3/mockito-core-3.3.3.jar!/org/mockito/Answers.class
  Last modified Mar 13, 2020; size 2582 bytes
  MD5 checksum 001d1b92852a41c0f732f007b31d97ac
  Compiled from "Answers.java"
public final class org.mockito.Answers extends java.lang.Enum implements org.mockito.stubbing.Answer
  minor version: 0
  major version: 52

所以和idea的配置无关

解决

改用低版本

        
            org.mockito
            mockito-core
            2.28.2
            test
        

你可能感兴趣的:(java)