Spring Boot gradle 构建 - 无效源版本:11

2024-03-09

我正在尝试使用以下命令构建我的 Spring Boot 项目:

./gradlew build

但它不断抛出这个错误:

'Execution failed for task ':compileJava'. invalid source release: 11'.

我的项目使用的是 Java 版本 11,IntelliJ Java 版本也设置为 11。

这是我迄今为止在 IntelliJ 上所做的 Java 版本设置:

  1. Settings - Build, Execution, Deployment - Build Tools - Gradle
    -> set to 11. enter image description here

  2. Settings - Build, Execution, Deployment - Compiler - Java Compiler - Project bytecode version
    -> set to 11. enter image description here

  3. java -version command on IntelliJ Terminal
    -> set to 11.0.12
    enter image description here

  4. Project Structure - Project Settings - Project - Project SDK: -> set to 11.
    enter image description here

  5. Project Structure - Project Settings - Modules - Module SDK: -> set to 11.
    enter image description here

  6. Project Structure - Platform Settings - SDKs - JDK home path:
    -> set to 11.
    enter image description here

  7. System Environment path - JAVA_HOME
    -> set to 11.
    enter image description here

  8. build.gradle - sourceCompatibility, targetCompatibility
    -> set to 11.
    enter image description here

当我跑步之后

./gradlew build

result
enter image description here

我想我已经尽力了。还有其他设置我可以尝试吗?


有2种解决方案。发生该问题的原因可能是 Gradle Wrapper 尝试在 Java_home 中查找 JDK 11,但未能在那里找到它。我不认为这是因为您使用了一些不支持 jdk11 的旧的已弃用依赖项。

解决方案1

明确提及您想要在终端上使用的 JDK。 例如,代替

./gradlew build

Use

./gradlew build -Dorg.gradle.java.home=yourjdk11homepath

你的路径可能是这样的:

C:\\Program Files\\OpenJDK\\jdk-11.0.3

解决方案2

如果您不想在使用 gradle 包装器构建项目时应用解决方案1,则可以在 gradle.properties 文件中设置该选项。

在与 build.gradle 和 gradlew 文件相同的目录级别上,make

gradle.properties

文件并写入以下内容:

org.gradle.java.home=yourjdk11homepath

同样,您的路径可能类似于:

C:\\Program Files\\OpenJDK\\jdk-11.0.3
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Boot gradle 构建 - 无效源版本:11 的相关文章

随机推荐