I can build the application (Kotlin+Spring+Spring Cloud) but I can't start it. Based on what I searched around it is related to incompability among Spring dependencies. I found someone facing similar issue as mine but after applying its solution I keep getting same issue other question
I tried also the the trick suggested with Spring Initializr but I got nothing when I type spring-cloud-starter
I guess the issue will fix when I set correct versions for:
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")
Here is my 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"
}
and its gradle.properties
springVersion=2.3.4.RELEASE
kotlinVersion=1.4.10
projectGroupId=com.mycomp
projectVersion=0.0.1
jacocoVersion=0.8.7
artifactoryContextUrl=xxx
The version you have declared for your spring cloud dependency (2.2.9.RELEASE
) is not compatible with spring boot 2.4. You need at least 3.0.0 See the table on https://spring.io/projects/spring-cloud -- specifically follow the link to the spring cloud 2020 releases since that's what corresponds to spring boot 2.4. I think this is likely the cause of your issue, but I have a few other suggestions to help keep things in sync.
I see kotlin version 1.4.10 but spring.kotlin version 1.5.20 and they usually keep lock step with one another, so it's best to at least use the same major version of both (in this case, 1.5.x) i.e. in your gradle.properties update the kotlin version to 1.5.x, and then in the build.gradle use
plugins {
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id("org.springframework.boot") version "2.5.4"
kotlin("jvm") version "1.5.30"
kotlin("kapt") version "1.5.30"
kotlin("plugin.spring") version "1.5.30"
}
Also note the updated spring dependency management version. Since you've declared the spring boot version, and you're using the dependency management plugin, you should let it pull in the versions that it wants -- you shouldn't declare the $springVersion on your dependencies, and you don't need the springVersion variable in your gradle.properties. The dependency management will pull in the proper version, which is already being done for your webflux dependency. This part is the second most likely cause of your problem.
If you're absolutely sure that the versions you have declared are compatible with one another, make sure an older version of cloud isn't being unexpectedly pulled in.
./gradlew dependencies --configuration compileClasspath
or
./gradlew -q dependencyInsight --dependency spring-cloud-starter-openfeign --configuration compileClasspath
If you're able to tease out the culprit that's bringing in the older version, you can prevent the older version from being pulled in transitively. In the snippet below, I'm omitting logger because I prefer log4j2, but you can substitute the old package, and if you're declaring the same package with a newer version, it'll be preferred
configurations {
all {
exclude(group = "org.springframework.boot", module = "spring-boot-starter-logging") // Prefer log4j2
}
}