You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将IntelliJ Java项目从Java 9降级到Java 8后仍遇无效源版本错误

Fixing "invalid source release: 1.9" After Downgrading to Java 8 in IntelliJ

Looks like the core issue here is that your pom.xml doesn’t explicitly define Java version constraints—Maven might still be defaulting to Java 9 under the hood, even after you tweaked IntelliJ’s settings. Let’s work through this step by step:

1. Update Your pom.xml to Enforce Java 8

Add the maven-compiler-plugin to your build configuration to lock in Java 8 for both source code compatibility and compiled output. Here’s your updated pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>groupId</groupId>
    <artifactId>VIN_API</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!-- Add this section to set Java 8 as the required version -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version> <!-- Use a stable, recent version -->
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <release>8</release> <!-- Ensures compatibility with Java 8 runtime -->
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2. Double-Check IntelliJ Project Settings

Even if you adjusted these earlier, confirm everything aligns with Java 8:

  • Go to File → Project Structure → Project:
    • Set Project SDK to your installed Java 8 JDK
    • Set Project language level to 8 - Lambdas, type annotations etc.
  • Go to File → Project Structure → Modules:
    • For every module in your project, set Language level to 8 - Lambdas, type annotations etc.

3. Fix Run/Debug Configurations

Your run setup might still be pointing to Java 9:

  • Click the run configuration dropdown in IntelliJ’s top-right corner → Edit Configurations
  • Select your application’s run configuration
  • Under the Configuration tab, set JRE to your Java 8 JDK

4. Reload Maven Project

After updating the pom.xml, tell IntelliJ to pick up the new settings:

  • Open the Maven tool window (usually on the right sidebar)
  • Click the Reload All Maven Projects button (the circular arrow icon)
  • Or right-click your project in the Project view → Maven → Reload Project

5. Clear IntelliJ Caches (If Issues Persist)

Old cached settings can sometimes stick around:

  • Go to File → Invalidate Caches...
  • Select Invalidate and Restart to clear caches and reboot the IDE

The critical point here is that Maven doesn’t automatically inherit IDE settings—defining the Java version in your pom.xml ensures consistency across all build environments (IDE, command line, CI/CD pipelines).

内容的提问来源于stack exchange,提问作者user9057492

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:09:28