java: Compilation failed: internal java compiler error和无效的源发行版解决

原因:主要是因为jdk版本不一致问题       

  • 1. 编译版本不匹配
  • 2. 当前项目jdk版本不支持       

1、首先查看项目的jdk

File ->Project Structure->Project Settings ->Project

                 1.8必须对应8

查看当前工程(module)的jdk和项目的是否相同

2、IDEA中使用Maven构建项目是Target bytecode version自动变为1.5   因为maven中没有指定jdk,所以才会扫描为默认的jdk版本  查看设置java编译器版本(Target bytecode version)

File–>Setting–>Build,Execution,Deployment–>Compiler–>Java Compiler 设置相应Module

         将target bytecode version的合适版本如:jdk1.8    将上面的1.5改为1.8

解决方案:

在pom.xml中添加maven-compiler-plugin这样就不会自动变为1.5了

     <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
      </plugin>

Guess you like

Origin blog.csdn.net/m0_46979453/article/details/120604131