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

Spring Boot 3.1.1项目Linux编译失败Windows正常问题求助

问题根因分析
  1. Maven Compiler Plugin参数处理逻辑变化
    Spring Boot 3.1.1搭配的maven-compiler-plugin 3.11.0默认依赖maven.compiler.release参数,该参数对应javac的--release选项,要求JDK提供完整的版本兼容性支持;而3.0.8版本搭配的3.10.1插件依赖source/target参数,对JDK工具链的要求更低。

  2. Linux环境JDK工具链不完整
    AlmaLinux 8.7上的Red Hat OpenJDK大概率是精简版(如headless或仅JRE),缺少--release选项所需的完整编译组件。--release参数需要JDK包含完整的版本配置数据,部分精简JDK会省略这部分内容,导致编译时抛出release version 17 not supported错误。Windows环境的OpenJDK是完整开发版,支持该参数,因此编译正常。

解决方案
  • 方案1:显式覆盖编译参数
    在项目pom.xml中添加以下配置,用source/target替代release参数:

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <maven.compiler.release/> <!-- 清空默认的release属性 -->
    </properties>
    

    或者直接配置maven-compiler-plugin:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                    <release/>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
  • 方案2:安装完整JDK开发包
    在AlmaLinux 8.7上安装完整的OpenJDK 17开发包,执行命令:

    dnf install java-17-openjdk-devel
    

    该包包含完整的编译工具链,支持--release参数,可解决版本不支持问题。

  • 方案3:降级Spring Boot版本
    回退到Spring Boot 3.0.8版本,此时maven-compiler-plugin 3.10.1使用source/target参数,适配性更强,无需修改环境即可跨平台编译。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 11:37:20