简体   繁体   English

Java Maven 项目“不再支持源选项 5。使用 6 或更高版本。”

[英]Java Maven Project "Source option 5 is no longer supported. Use 6 or later."

I'm following a PluralSight course, "Spring Framework: Spring Fundamentals" by Bryan Hansen.我正在学习 Bryan Hansen 的 PluralSight 课程“Spring Framework:Spring Fundamentals”。 I've followed the demo precisely (I believe) but am getting the error message "Error:java: Source option 5 is no longer supported. Use 6 or later.".我已经精确地遵循了演示(我相信),但收到错误消息“错误:java:不再支持源选项 5。使用 6 或更高版本。”。

I'm using the latest version of IntelliJ, with the following configurations:我使用的是最新版本的 IntelliJ,配置如下:

  • Under "Preferences > Build, Execution, Deployment > Compiler > Java Compiler" I have the project bytecode version set to Java 11 and the per-module bytecode version to "Same as language level".在“首选项 > 构建、执行、部署 > 编译器 > Java 编译器”下,我将项目字节码版本设置为 Java 11,将每个模块的字节码版本设置为“与语言级别相同”。
  • Under "File > Project Structure > Project" I have the project SDK set to 11 and project language level set to 11 as well.在“文件 > 项目结构 > 项目”下,我将项目 SDK 设置为 11,项目语言级别也设置为 11。
  • Have my pom.xml with the following build settings:让我的 pom.xml 具有以下构建设置:

    <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>11</source>
                        <target>11</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>

I've looked at some other similar posts, and they seem to sometimes have the above configuration as 1.6 instead of 11, but I'm trying to follow this tutorial closely.我看过其他一些类似的帖子,他们似乎有时将上述配置设为 1.6 而不是 11,但我正在尝试密切关注本教程。 Am still curious as to the discrepancy here.我仍然很好奇这里的差异。

Not sure what's casuing this error to be thrown, as far as I can tell I've got everything set up correctly but clearly that's not the case.不知道是什么导致了这个错误被抛出,据我所知,我已经正确设置了一切,但显然情况并非如此。 Any help would be appreciated.任何帮助,将不胜感激。

Fixed this by doing the following.通过执行以下操作修复了此问题。

Project Structure > Modules (under Project Settings) > Set language level to 11项目结构 > 模块(在项目设置下)> 将语言级别设置为 11

Hope this helps someone who runs in to the same issue.希望这可以帮助遇到相同问题的人。

You can also edit the <ProjectName>.iml file (it is created automatically in your project folder if you're using IntelliJ) directly by changing the following line,您还可以通过更改以下行直接编辑<ProjectName>.iml文件(如果您使用 IntelliJ,它将在您的项目文件夹中自动创建),

From: <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">来自: <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">

To: <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">至: <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">

As your approach is also meaning to edit this file.由于您的方法也意味着编辑此文件。 :) :)

I am following the Jenkov tutorialYour First Maven Project and got the same error when attempting to execute the command mvn package .我正在关注 Jenkov 教程Your First Maven Project并在尝试执行命令mvn package时遇到相同的错误。 In this tutorial we are not using an IDE, but instead are working at the CLI, and have only a pom.xml and a HelloWorld.java file, both of which can be made with a simple text editor like Notepad .在本教程中,我们没有使用 IDE,而是在 CLI 中工作,并且只有一个pom.xml和一个HelloWorld.java文件,这两个文件都可以使用Notepad等简单的文本编辑器制作。

I don't fully understand, but I think the error message is referring to the version of Java that is being invoked.我不完全理解,但我认为错误消息是指正在调用的 Java 版本。 If this was the intention, the error message certainly could have been better crafted!如果这是故意的,那么错误消息当然可以更好地制作! Hopefully someone will correct me if I am wrong.如果我错了,希望有人能纠正我。

Maybe related, I've noticed that certain operations on my system default to assuming Java 1.5, even though this version of Java isn't installed on my PC.也许与此相关,我注意到我的系统上的某些操作默认假定为 Java 1.5,即使我的 PC 上未安装此版本的 Java。 (For example, when creating a new Maven project in Eclipse.) (例如,在 Eclipse 中创建新的 Maven 项目时。)

In any event, specifying a java version that is 7 or later explicitly seems to be the answer.无论如何,明确指定 7 或更高版本的 java 版本似乎是答案。 I have Java 15 on my laptop, so I specified the Java 15 version of Java by adding the following to the pom.xml .我的笔记本电脑上有 Java 15,所以我通过将以下内容添加到pom.xml来指定 Java 15 版本的 Java。

<properties>
    <java.version>15</java.version>
    <maven.compiler.source>15</maven.compiler.source>
    <maven.compiler.target>15</maven.compiler.target>
</properties>

However, I also tried specifying 1.7 or 1.8, and these worked as well.但是,我也尝试指定 1.7 或 1.8,并且这些都有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 另一个 Maven “不再支持源选项 6。使用 7 或更高版本。” - Another Maven "Source option 6 is no longer supported. Use 7 or later." Intelij Maven:错误:不再支持源选项 6。 使用 7 或更高版本。 还有解决方案吗? - Intelij Maven : error: Source option 6 is no longer supported. Use 7 or later. Is there anymore solutions? 错误:不再支持源选项 6。 使用 7 或更高版本。 反编译 MCP 时 - error: Source option 6 is no longer supported. Use 7 or later. When decompiling MCP 在Eclipse中无法正常运行时,无法在jenkins中编译maven项目,“不再支持源选项6。 使用7或更高版本” - Unable to compile maven project in jenkins while it is working fine in the eclipse “Source option 6 is no longer supported. Use 7 or later” 在 GWT 项目中运行“ant gwtc”会出现错误“Source option 5 is no longer supported. Use 7 or later” - Running "ant gwtc" in GWT project gives error "Source option 5 is no longer supported. Use 7 or later" java -xbootclass 路径不再是受支持的选项 - java -xbootclass path is no longer a supported option 如何处理“不再支持 resteasy.scan。使用 servlet 3.0 容器和 ResteasyServletInitializer”错误 - How to handle "resteasy.scan is no longer supported. Use a servlet 3.0 container and the ResteasyServletInitializer" Error 不支持文本对象。 Java Excel API - Text Object not supported. Java excel API Eclipse、Maven:模块在 -source 8 中不受支持(使用 -source 9 或更高版本来启用模块) - Eclipse, Maven: Modules are not supported in -source 8 (use -source 9 or higher to enable modules) Eclipse Java Project和Maven的多个源文件夹 - Multiple Source Folders for Eclipse Java Project & Maven
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM