原因
IDEA默认把项目的源代码版本设置为jdk1.5,目标代码设置为jdk1.5
解决方案
你可能会搜索到很多的解决方案,比如下面这个比较优秀的一篇
https://blog.youkuaiyun.com/gdsgdh308227363/article/details/82251655
这些都是在IDEA里面进行一系列复杂的设置,而且每次弄一个新的工程如果你有强迫症不想看到这个提示的话都得为每个工程设置一遍,那么有没有什么一劳永逸的方法呢?答案是有的。
修改Maven的Settings.xml文件添加如下内容
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
什么?不知道Setting.xml文件在哪里?那赶快去百度一下maven .m2这个东西
在这里我就不再赘述。下面顺便带大家展示一下我的Settings.xml文件的相关配置
尤其是网络优化的配置哈哈。
网络优化仓库是用nexus repository弄的,有兴趣的可以去了解一下
话不多说上代码
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- the path to the local repository - defaults to ~/.m2/repository
-->
<!-- <localRepository>/path/to/local/repo</localRepository>
-->
<mirrors>
<mirror> <!--Send all requests to the public group -->
<id>maven</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.qingguatang.com/nexus/content/groups/open/</url>
</mirror>
</mirrors>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>maven</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>maven</id>
<!--Override the repository (and pluginRepository) "central" from the Maven Super POM
to activate snapshots for both! -->
<repositories>
<repository>
<id>central</id>
<url>http://maven.qingguatang.com/nexus/content/groups/open/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://maven.qingguatang.com/nexus/content/groups/open/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
<pluginGroups>
<pluginGroup>org.sonatype.plugins</pluginGroup>
</pluginGroups>
<servers>
<server>
<id>maven</id>
<username>qingguatang</username>
<password>qingguatang</password>
</server>
</servers>
</settings>