在IntelliJ中,当我对从www.example.com下载的新项目进行干净的构建时start.spring.io,它给出了一个错误。
Spring Configuration on start.spring.io
我已经安装了直接从IntelliJ下载的Java 17 JDK(Amazon Corretto)
在终端中,运行命令:第一个月
导致以下错误:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'learn-spring-framework'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.1.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.1
> No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.1 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 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 declares a runtime of a component, 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 '7.6')
- Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.1 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 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.1 declares a runtime of a library, 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 '7.6')
- Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 declares a runtime of a library, 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 '7.6')
- Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 declares a runtime of a component, 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 '7.6')
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
先谢谢你的帮助
尝试:
1.确保项目在File -> Project Structure
下使用Java 17 SDK
1.确保Gradle JVM指向IntelliJ IDEA -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
下的Java 17 SDK
1.尝试将build.gradle
文件更改为
sourceCompatibility = (11 or 17)
targetCompatibility = (11 or 17)
java {
toolchain {
languageVersion = JavaLanguageVersion.of( (11 or 17) )
}
}
奇怪的是,如果我点击IntelliJ上的“播放”按钮,这个项目就构建得很好
1条答案
按热度按时间8ljdwjyq1#
Spring Boot 3
要求最低版本为JDK 17
。如果您想使用
JDK 17
或更高版本配置InteliJ with gradle,则需要以下配置。1.文件-〉项目结构-〉项目-〉项目SDK-〉指定jdk为17或更高版本
1.您还需要以下配置。文件-〉设置-〉构建、执行、部署-〉构建工具-〉Gradle -〉Gradle JVM并指定jdk为17或更高版本。
请记住,上述配置适用于
gradle
的嵌入式版本,InteliJ
将其用作嵌入式工具。不是配置为从Terminal
运行的版本为了使用
gradle
终端的嵌入式工具版本(已根据上述配置使用Jdk 17
进行设置),您需要运行以下命令:这应该足够执行您的项目。
否则如果您坚持使用终端执行gradle命令,然后你需要在环境变量中做所有必要的调整。2要做这些,请进入文件-〉设置-〉工具-〉终端-〉环境变量。3要使环境改变生效,你必须重新启动InteliJ窗口。重启后可以使用
gradle -version
命令确认是否设置了正确的JVM
和gradle
版本,也可以使用java -version
查看终端指向哪个JDK。Spring Boot
Initializer还提供了一个可移植的gradle
文件,该文件兼容于运行项目。因此,如果您在环境属性下有另一个gradle安装在您的系统中,您可以使用上述命令检测并删除,以便您可以只使用本地随附的一个。