I have a Spring Boot 3 project with Gradle and Java 17. I want to work with it using VS Code. I have the Java extension pack, the Spring Boot extension pack and the gradle extension in VS Code.
I can use the same project without problems in Eclipse. I also tried using a new project from start.spring.io. The projects work with the following configurations:
- Maven + Java 11 + Spring Boot 2.7.14
- Maven + Java 17 + Spring Boot 3.1.2
- Gradle + Java 11 + Spring Boot 2.7.14
The log shows the following error, when i try to open the project:
!SESSION 2023-08-09 20:32:19.690 -----------------------------------------------
eclipse.buildId=unknown
java.version=17.0.7
java.vendor=Eclipse Adoptium
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-09 20:32:29.890
!MESSAGE Finished creating the Java project jdt.ls-java-project
!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-09 20:32:31.142
!MESSAGE Importing Gradle project(s)
!ENTRY org.eclipse.jdt.ls.core 1 0 2023-08-09 20:32:31.143
!MESSAGE No previous Gradle project at /home/username/Documents/tmp/testb3j17g, it must be synchronized
!ENTRY org.eclipse.buildship.core 2 3 2023-08-09 20:32:42.643
!MESSAGE Synchronize project testb3j17g failed due to an error connecting to the Gradle build.
!STACK 0
org.gradle.tooling.BuildActionFailureException: The supplied phased action failed with an exception.
at ...
Caused by: org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'testb3j17g'.
at ...
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':classpath'.
at ...
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.1.2.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.1.2
Caused by: org.gradle.internal.component.NoMatchingConfigurationSelectionException: No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.1.2 was found. The consumer was configured to find a library for use during runtime, compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.2.1' but:
- Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.2 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
- Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.2 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
- Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.2 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
- Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.2 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
- Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.2 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
- Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.2 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
at ...
!ENTRY org.eclipse.jdt.ls.core 4 0 2023-08-09 20:32:43.292
!MESSAGE Could not fetch model of type 'Map' using connection to Gradle installation '/usr/share/java/gradle'.
!STACK 0
org.gradle.tooling.BuildException: Could not fetch model of type 'Map' using connection to Gradle installation '/usr/share/java/gradle'.
at ...
Caused by: org.gradle.internal.exceptions.LocationAwareException: A problem occurred configuring root project 'testb3j17g'.
at ...
Caused by: org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'testb3j17g'.
at ...d$4(DefaultBuildTreeLifecycleController.java:98)
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':classpath'.
at ...
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.1.2.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.1.2
Caused by: org.gradle.internal.component.NoMatchingConfigurationSelectionException: No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.1.2 was found. The consumer was configured to find a library for use during runtime, compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.2.1' but:
- Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.2 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
- Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.2 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
- Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.2 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
- Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.2 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
- Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.2 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
- Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.2 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
After reading some other questions (like this one or that one), I thought gradle uses java 11 but gradle --version
gives the following output:
$ gradle --version
------------------------------------------------------------
Gradle 8.2.1
------------------------------------------------------------
Build time: 2023-07-10 16:30:34 UTC
Revision: <unknown>
Kotlin: 1.8.20
Groovy: 3.0.17
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 17.0.8 (Oracle Corporation 17.0.8+7)
OS: Linux 6.4.4-arch1-1 amd64
I also set the VS Code setting Java › Import › Gradle › Java: Home
to the JDK-17. What I find strange is that gradle build is working fine and also in the gradle view in VS Code the Spring Boot dependencies are listed.