将Spring Boot应用程序迁移到最新的Java版本(Java 15) [英] Migrating Spring Boot Applications to the Latest Java Version (Java 15)

查看:100
本文介绍了将Spring Boot应用程序迁移到最新的Java版本(Java 15)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设置为使用Java 8和Kotlin的spring boot项目.我想将项目迁移到Java 15,但是不幸的是,我还没有找到任何有用的文档.

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.

到目前为止,我已经能够将Spring引导版本从2.3.3.RELEASE升级到版本2.4.0,并且可以基于使用spring initializr创建的项目示例引用该项目以在jvmTarget中使用Java 14.

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.

但是,我没有找到升级到Java 15的方法.任何想法都将不胜感激.

However, I didn't the find a way to upgrade to Java 15. Any ideas would be very appreciate it.

这是我的build.gradle的样子:

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"
 }
}
....

注意:为build.gradle中的kotlinOptions属性更改jvmTarget = 15时,出现以下异常:未知JVM目标版本:15支持的版本:1.6、1.8、9、10、11、12,12,14.这是否意味着Kotlin不支持Java 15?

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?

推荐答案

JDK 15需要Gradle 6.7.x,如果尚未更新,请先更新Gradle.

JDK 15 requires Gradle 6.7.x, please update Gradle first, if you haven't done so, yet.

我建议您使用新的工具链功能摇篮.如果无法在主机系统上检测到该代码,它将下载所需的JDK来构建您的代码,以确保使用所需的JDK版本执行该构建.通过混合团队,这也简化了在不同环境中的正确构建.

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))
    }
}

这不能与 java.sourceCompatibility java.targetCompatibility 一起使用,您需要删除这些配置.

This does not work together with java.sourceCompatibility and java.targetCompatibility, you would need to remove these configurations.

这篇关于将Spring Boot应用程序迁移到最新的Java版本(Java 15)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆