Ton*_*hen 8 intellij-idea gradle spring-boot java-17
在 IntelliJ 中,当我对从 start.spring.io 下载的新项目进行干净构建时,会出现错误。
我已经安装了直接从 IntelliJ 下载的 Java 17 JDK (Amazon Corretto)
在终端中,运行命令:./gradlew clean build
导致以下错误:
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
Run Code Online (Sandbox Code Playgroud)
先谢谢您的帮助
尝试过:
File -> Project Structure
IntelliJ IDEA -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
build.gradle
文件sourceCompatibility = (11 or 17)
targetCompatibility = (11 or 17)
java {
toolchain {
languageVersion = JavaLanguageVersion.of( (11 or 17) )
}
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如果我只需单击 IntelliJ 上的“播放”按钮,该项目就可以正常构建
Pan*_*kos 17
Spring Boot 3
需要最低版本JDK 17
。
如果您想使用 gradleJDK 17
或更高版本配置 InteliJ,则需要以下配置。
请记住,上述配置适用于gradle
用作InteliJ
嵌入式工具的嵌入式版本。不是配置为运行的那个Terminal
为了使用gradle
已经根据上述配置设置的终端嵌入式工具版本Jdk 17
,您需要运行如下命令:
这应该足以执行您的项目。
否则如果你坚持使用终端执行gradle命令,那么你需要对环境变量进行所有必要的调整。为此,请进入File -> Settings -> Tools -> Terminal -> Enviroment Variables。要使环境更改生效,您必须重新启动 InteliJ 窗口。重启后可以用gradle -version
命令确认是否设置了正确的版本JVM
。gradle
您还可以使用java -version
查看终端指向的 JDK。Spring Boot
初始化程序还提供一个gradle
与运行项目兼容的可移植文件。因此,如果您的系统中安装了环境属性下的另一个 gradle,您可以使用上述命令进行检测并删除,以便您只能使用已发布的本地版本。
归档时间: |
|
查看次数: |
14154 次 |
最近记录: |