I recently started a new Spring Boot Gradle project, using IntelliJ. When making the project, I chose Java 17 as the project Java version. My build.gradle
file had sourceCompatibility = '17'
, but my JAVA_HOME
environment variable is set to Java 11 and I don't really want to use Java 17.
I tried changing sourceCompatibility
to 11
, and went into
File -> Project Structure -> Project Settings -> Project
to change the SDK to 11 as well.
Whenever I click the "run" button in IntelliJ, as well as when I try to build my project in command line with ./gradlew clean build
, I get a bunch of errors, mostly complaining about compatibility issues. They all read almost the same; here is the beginning of the errors from the failed build:
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.1-SNAPSHOT.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.1-SNAPSHOT:20221222.181044-39
> No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.1-SNAPSHOT:20221222.181044-39 was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.6' but:
- Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1-SNAPSHOT declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
- Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1-SNAPSHOT declares a runtime of a component, and its dependencies declared externally:
I don't want to have to start my project over just to fix this compatibility issue. I'd prefer not to have to switch between Java versions (I know about jEnv, just prefer to leave everything on my computer set to Java 11 for now). Is there a way to fix this project without trashing it and redoing it?
Ctrl + Alt + S > Build, Execution, Deployment > Gradle > Gradle JVM -> java 11 photo x