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

Bash中Maven构建正常,IntelliJ执行Makefile报JDK17不支持

问题:IntelliJ中点击Makefile的do-build报错JDK版本不支持

我对Maven不太熟悉,对Makefile更是陌生。我有一个Makefile,其中包含do-build步骤:

do-build:
    mvn clean install -DskipTests -Dspotbugs.skip=true -Dpmd.skip=true -Dmaven.javadoc.skip=true

在bash shell中,直接运行make do-build或指定的Maven命令都能正常工作。但在IntelliJ中查看该Makefile时,do-build旁的gutter显示绿色">"图标,点击该图标却报错Fatal error compiling: error: release version 17 not supported,我无法解决此问题。

已排查的设置

  • update-alternatives --config java已正确设置为corretto-17
  • which java指向正确的Java二进制文件
  • $JAVA_HOME指向该二进制文件
  • IntelliJ设置>Java编译器>项目字节码版本设为17
  • IntelliJ设置>Maven>导入器JDK设为17
  • IntelliJ项目结构>项目:SDK和语言级别均设为17
  • IntelliJ项目结构>模块:语言级别设为17
  • .idea/misc.xml中的component元素列出JDK17
  • pom.xml文件配置如下:
    • properties > java.version: 17
    • properties > maven.compiler.source: ${java.version}
    • properties > maven.compiler.target: ${java.version}
    • build > plugins > plugin > artifactId maven-compiler-plugin > configuration > source: ${java.version}
    • build > plugins > plugin > artifactId maven-compiler-plugin > configuration > target: ${java.version}
  • IDE的运行时JDK设为17
  • 已尝试清理IntelliJ缓存等操作

简言之,我已排查完所有能想到的设置,但问题仍存在。这是全新安装的Ubuntu MATE 22.04系统,请问问题出在哪里?

可能的解决方向

  1. 检查IntelliJ的Makefile运行环境变量
    IntelliJ运行Makefile时,可能没有继承系统的JAVA_HOME或PATH变量。可以在IntelliJ中打开「Run/Debug Configurations」,找到对应的Makefile配置,在「Environment variables」里手动添加JAVA_HOME指向你的corretto-17路径(比如JAVA_HOME=/usr/lib/jvm/amazon-corretto-17.x.x),同时确保PATH包含$JAVA_HOME/bin。

  2. 在Makefile中显式指定Java环境
    修改Makefile的do-build目标,提前设置Java相关变量,强制Maven使用指定JDK:

    do-build:
        export JAVA_HOME=/usr/lib/jvm/amazon-corretto-17.x.x && export PATH=$$JAVA_HOME/bin:$$PATH && mvn clean install -DskipTests -Dspotbugs.skip=true -Dpmd.skip=true -Dmaven.javadoc.skip=true
    

    替换成你实际的corretto-17安装路径。

  3. 检查Maven全局配置
    查看~/.m2/settings.xml或项目内的settings.xml,确认是否在<profiles>节点中配置了全局的JDK版本参数,覆盖了项目pom.xml的设置。

  4. 验证IntelliJ的Make工具配置
    进入IntelliJ设置>Build, Execution, Deployment>Build Tools>Makefile,检查「Make executable」是否为系统默认的make,同时确认没有添加可能干扰环境变量的额外参数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 19:43:24