我在VSCode中创建了一个新的Maven项目。当我尝试运行文件时,出现此错误The compiler compliance specified is 1.7 but a JRE 13 is used
但是没有有关如何解决该错误的说明。我该怎么办?
这些是我安装的VSC插件:
最佳答案
要解决此问题,您必须手动更新pom.xml文件。您需要做的所有事情都在doc, section "Java 9 or later"中进行了说明。这是要遵循的步骤。
默认的pom.xml文件提供以下信息:
旧版本-pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
如您所见,Maven使用了一个过时的插件来与Java 1.7的maven.compiler.source一起使用。在这里您要更新插件并指定Java 13的用法。按如下所示修改pom.xml:新的解决方案版本-pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>13</maven.compiler.release>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
现在,不要忘记通过右键单击pom.xml文件,然后单击Update Project Configuration
或执行Alt+Shift+U
并等待更改应用来更新VSCode配置。通常,“问题”部分应为
No problems have been detected in the workspace so far.
关于java - VSCode Maven错误 `The compiler compliance specified is 1.7 but a JRE 13 is used`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60498063/