Reputation: 4299
I have a spring boot project set up to use Java 8 and Kotlin. I want to migrate the project to Java 15, but unfortunately I haven't found any documentation useful for that purpose.
So far i was able to upgrade my Spring boot version from 2.3.3.RELEASE to version 2.4.0 and reference the project to use Java 14 in jvmTarget based on a project example created using the spring initializr.
However, I didn't the find a way to upgrade to Java 15. Any ideas would be very appreciate it.
This is how my build.gradle looks like:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.lang.System.getenv
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("org.jmailen.gradle:kotlinter-gradle:3.0.2")
}
}
plugins {
id("org.springframework.boot") version "2.4.0"
id("io.spring.dependency-management") version "1.0.10.RELEASE"
kotlin("jvm") version "1.4.0"
kotlin("plugin.spring") version "1.4.0"
id ("org.owasp.dependencycheck") version "5.3.2"
id ("com.github.spotbugs") version "4.5.0"
id ("org.jmailen.kotlinter") version "3.0.2"
`jacoco`
}
tasks.named<org.springframework.boot.gradle.tasks.run.BootRun>.
("bootRun") {
args("--spring.profiles.active=local")
}
jacoco {
toolVersion = "0.8.6"
}
group = "au.project"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
maven {
url = uri("https://...")
credentials {
username = getenv("ARTIFACTORY_USER")
password = getenv("ARTIFACTORY_PASSWORD")
}
}
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-
webflux")
implementation("com.fasterxml.jackson.module:jackson-module-
kotlin")
implementation("io.github.microutils:kotlin-logging:1.8.3")
implementation("io.projectreactor.kotlin:reactor-kotlin-
extensions")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
implementation("org.owasp:dependency-check-gradle:5.3.2")
implementation("org.springdoc:springdoc-openapi-kotlin:1.4.8")
implementation("org.springdoc:springdoc-openapi-webflux-ui:1.4.8")
developmentOnly("org.springframework.boot:spring-boot-devtools")
testImplementation("org.springframework.boot:spring-boot-starter-
test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
testImplementation("io.projectreactor:reactor-test")
testImplementation("com.github.tomakehurst:wiremock-jre8:2.27.2")
testImplementation("com.openpojo:openpojo:0.8.6")
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "14"
}
}
....
Note: Chaning the jvmTarget = 15 for the kotlinOptions property within the build.gradle, I am getting the following exception: "Unknown JVM target version: 15 Supported version: 1.6, 1.8, 9,10,11,12,12,14. Does it means Kotlin does not support Java 15?
Upvotes: 3
Views: 5100
Reputation: 20132
JDK 15 requires Gradle 6.7.x, please update Gradle first, if you haven't done so, yet.
I recommend you use the new toolchain feature of Gradle. It will download the required JDK to build your code, if it cannot detect it on the host system, to guarantee that the build is executed with the required JDK version. This also simplifies the right build in different environments with a mixed team.
java {
toolchain {
// automatically download a jdk for the build if not available
languageVersion.set(JavaLanguageVersion.of(11))
}
}
This does not work together with java.sourceCompatibility
and java.targetCompatibility
, you would need to remove these configurations.
Upvotes: 4
Reputation: 16539
First of all, you need to upgrade to latest version of Gradle, i.e (6.7.x) to support JDK 15.
Add or update the following lines in build.gradle :
java.sourceCompatibility = JavaVersion.VERSION_15
java.targetCompatibility = JavaVersion.VERSION_15
Upvotes: 2