java: error: invalid source release: 17

1. Error reporting

java: error: invalid source release: 17
Error screenshot

2. Problem background

(1) Version information configured in the POM file: spring boot: 3.1.0, jdk: 17

pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>first-spring-boot-project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>first-spring-boot-project</name>
    <description>first-spring-boot-project</description>
    <properties>
        <java.version>17</java.version>
    </properties>

(2) The JDK version configured in the "Project Structure" window
insert image description here
insert image description here

3. Reason Analysis

POM文件中配置的JDK版本信息inconsistent with "Project Structure" 窗口配置的JDK版本.
For example, in this case, the JDK version configured in the POM file is 17, but the JDK version configured in the "Project Structure" window is 1.8. The inconsistency between the two results in the above error.

4. Solutions

revise "Project Structure" 窗口配置的JDK版本. The specific operation is as follows:

Open the "Project Structure" window, and modify the JDK version under Project and Modules to keep it consistent with the version information configured in the POM file (for example, this project is JDK17). As shown below.
(1) Modify the JDK of the Project
insert image description here
(2) Modify the JDK of the Modules
insert image description here

appendix


There are two ways to open the "Project Structure" window:
Method 1: Find File -> Project Structure in the menu bar , and click to open the "Project Structure" window.
Method 2: Use the shortcut key: Ctrl+ Alt+ Shift+ S.

Guess you like

Origin blog.csdn.net/Shipley_Leo/article/details/131033785