【IDEA异常】idea创建项目target bytecode version默认为1.5,target bytecode version手动修改后经常自动变为默认值1.5

idea创建项目target bytecode version默认为1.5

一、问题描述

idea项目target bytecode version默认为1.5,修改 target bytecode version 为 1.8之后,下次编译又变为默认值1.5。

在这里插入图片描述

二、解决方案

2.1 方案一

Ctrl + Alt + S 快捷键打开 Settings 弹窗。
将 Settings => Build,Execution,Deployment => Java Compiler 的 target bytecode version 手动更改为1.8

手动改为 1.8之后点击,Apply 和 Ok 后编译成功。

在这里插入图片描述
但是下次启动项目,target bytecode version 又默认变为 1.5了。

此时在 pom.xml 中加上如下内容可能就成功

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

2.2 方案二

maven项目的pom.xml中没有parent标签,则target bytecode version为默认的1.5版本。

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.5.4</version>
</parent>

把parent标签添加上,target bytecode version变为1.8。完美解决。

本文完结!

猜你喜欢

转载自blog.csdn.net/weixin_44299027/article/details/131561114