У меня есть проект Spring Boot 3 с Gradle и Java 17. Я хочу работать с ним, используя VS Code. У меня есть пакет расширения Java, пакет расширения Spring Boot и расширение gradle в VS Code.
Я могу без проблем использовать тот же проект в Eclipse. Я также попытался использовать новый проект из start.spring.io. Проекты работают со следующими конфигурациями:
Журнал показывает следующую ошибку, когда я пытаюсь открыть проект:
!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')
Прочитав некоторые другие вопросы (например, этот или тот), я подумал, что gradle использует java 11, но gradle --version выдает следующий результат:
$ 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
Я также установил для параметра VS Code Java › Import › Gradle › Java: Home значение JDK-17. Что мне кажется странным, так это то, что сборка gradle работает нормально, а также в представлении gradle в VS Code перечислены зависимости Spring Boot.
Это настройка Gradle или VS Code?
Это помогло. Я установил конфигурации времени выполнения в VS Code, и теперь он работает. Спасибо! Вы хотите ответить на вопрос, чтобы я мог установить его как принятый ответ?
Я сделал ответ. Если вы не возражаете, вы можете нажать «✔», чтобы отметить мой ответ как принятый ответ. Это также поможет другим решить аналогичную проблему.




Вы можете настроить JDK для своего проекта с помощью конфигурации java.configuration.runtimes.
Пример:
"java.configuration.runtimes": [
{
"name": "JavaSE-1.8",
"path": "/usr/local/jdk1.8.0_201"
},
{
"name": "JavaSE-11",
"path": "/usr/local/jdk-11.0.3",
"sources" : "/usr/local/jdk-11.0.3/lib/src.zip",
"javadoc" : "https://docs.oracle.com/en/java/javase/11/docs/api",
"default": true
},
{
"name": "JavaSE-12",
"path": "/usr/local/jdk-12.0.2"
},
{
"name": "JavaSE-13",
"path": "/usr/local/jdk-13"
}
]
Это работает, когда я делаю это для JDK 17 :) спасибо
Вы настроили
java.configuration.runtimes?