我可以构建应用程序(Kotlin+Spring+Spring Cloud),但我无法启动它。根据我搜索的内容,它与 Spring 依赖项之间的不兼容有关。我发现有人面临与我类似的问题,但在应用其解决方案后,我不断遇到其他问题
我也尝试了 Spring Initializr 建议的技巧,但是当我输入 spring-cloud-starter 时我什么也没得到
我想当我为以下内容设置正确的版本时问题会解决:
id("org.springframework.boot") version "2.4.7"
id("io.spring.dependency-management") version "1.0.10.RELEASE"
implementation("org.springframework.boot:spring-boot-dependencies:${springVersion}")
implementation("org.springframework.boot:spring-boot-starter:${springVersion}")
implementation("org.springframework.boot:spring-boot-starter-web:${springVersion}")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.cloud:spring-cloud-starter-openfeign:2.2.9.RELEASE")
implementation("io.github.openfeign:feign-okhttp:10.2.0")
这是我的 gradle.build.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.jetbrains.kotlin.jvm") version "1.4.10"
id("org.jetbrains.kotlin.kapt") version "1.4.10"
kotlin("plugin.spring") version "1.5.20"
id("org.springframework.boot") version "2.4.7"
id("io.spring.dependency-management") version "1.0.10.RELEASE"
}
val kotlinVersion: String by project
val springVersion: String by project
val projectGroupId: String by project
val projectVersion: String by project
val jacocoVersion: String by project
group = projectGroupId
version = projectVersion
repositories {
mavenLocal()
...
mavenCentral()
}
// add dependencies
dependencies {
kapt(kotlin("stdlib", kotlinVersion))
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect", kotlinVersion))
compile("br.com.mycomp:lib-log:3.2.0-74")
implementation("org.springframework.boot:spring-boot-dependencies:${springVersion}")
implementation("org.springframework.boot:spring-boot-starter:${springVersion}")
implementation("org.springframework.boot:spring-boot-starter-web:${springVersion}")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.cloud:spring-cloud-starter-openfeign:2.2.9.RELEASE")
implementation("io.github.openfeign:feign-okhttp:10.2.0")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.2")
}
java {
sourceCompatibility = JavaVersion.toVersion("11")
}
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "11"
javaParameters = true
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "11"
javaParameters = true
}
}
}
springBoot {
mainClass.set("com.examplo.demo.DemoApplication.kt")
}
sourceSets {
main {
java {
srcDirs("build/generated/source/avro/main/java")
}
}
}
apply {
tasks.test {
useJUnitPlatform()
}
configurations {
all {
exclude(group = "junit", module = "junit")
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
exclude(group = "org.slf4j", module = "slf4j-log4j12")
}
}
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "11"
javaParameters = true
}
}
}
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
及其 gradle.properties
springVersion=2.3.4.RELEASE
kotlinVersion=1.4.10
projectGroupId=com.mycomp
projectVersion=0.0.1
jacocoVersion=0.8.7
artifactoryContextUrl=xxx