IDEA中maven项目的language level 修改后自动重置问题
问题:
我的JDK使用的是1.8,但是在IDEA中编写1.8特性的代码时却会爆红,而且编译也通不过,确定不是代码的问题后。转而发现了Language Level这个东西,IDEA中默认Language Level 5(即对应JDK1.5),打开Module Settings将Language level修改为8(即对应JDK1.8),但是重新刷新maven依赖时,又会变成Language Level 5。
解决方法:
通过指定maven项目的Language Level值,来防止每次自动重置Language Level。在maven项目的pom.xml 中添加如下内容即可:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>