错误:(185,13)java:在-source 1.5中不支持try-with-resources(使用-source 7或更高版本来启用try-with-resources)

Aye*_*era 4 java maven

在Java SDK 1.8中进行intelij maven编译,但显示自动更改为Java SDK 1.5并显示此错误

Dan*_*yen 5

你的pom.xml文件应该有这个,它将maven编译器指定为1.8

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)

要么

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)