Gradle:
plugins {
id 'org.springframework.boot' version '2.5.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-websocket'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
}
test {
useJUnitPlatform()
}
报错信息:
Cause: error: invalid source release: 17
解决方法:
intellij 中,将 Gradle JVM 设置为 Java 17,
依次点击,File -> Settings... -> Build, Execution, Deployment -> Build Tools -> Gradle
,选择使用的项目并将Gradle JVM设置为 java 17的版本。
或者
可以定义~/.gradle/gradle.properties
中org.gradle.java.home
的配置如下:
org.gradle.java.home=/path/to/jdk17
注意:Windows 用户文件位于C:\Users\<username>\.gradle\gradle.properties