2

Problem

I am trying to run the newest kotlin version (1.2.10) with also, the newest spring boot (2.0.0.M7). In the local enviroment everything is fine, however -boottime intellij cries :enter image description here

I have seen Outdated Kotlin Runtime, but in my opinion it is not connected so... That is suspicious because of my following build.gradle, where there is only one version of kotlin (only right one) [frontend is also gradle build but node.js one - angular, no kotlin deps]:

buildscript { ext { kotlinVersion = '1.2.10' springBootVersion = '2.0.0.M7' } repositories { mavenCentral() maven { url "https://repo.spring.io/snapshot" } maven { url "https://repo.spring.io/milestone" } maven { url "http://repo.spring.io/libs-milestone-local" } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}") classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}") classpath 'org.springframework:springloaded:1.2.6.RELEASE' } } apply plugin: 'kotlin' apply plugin: 'kotlin-spring' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' apply plugin: 'idea' group = 'com.witkups' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 idea { module { inheritOutputDirs = false outputDir = file("$buildDir/classes/main/") } } compileKotlin { kotlinOptions.jvmTarget = "1.8" } compileTestKotlin { kotlinOptions.jvmTarget = "1.8" } repositories { mavenCentral() maven { url "https://repo.spring.io/snapshot" } maven { url "https://repo.spring.io/milestone" } maven { url "http://repo.spring.io/libs-milestone-local" } } dependencies { compile project(":frontend") compile('org.springframework.boot:spring-boot-starter-actuator') compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.springframework.boot:spring-boot-starter-security') compile('org.springframework.boot:spring-boot-starter-webflux') compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") runtime('org.springframework.boot:spring-boot-devtools') runtime('com.microsoft.sqlserver:mssql-jdbc') compile('com.fasterxml.jackson.datatype:jackson-datatype-jsr310') compile('com.fasterxml.jackson.module:jackson-module-kotlin:2.9.2') compile("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}") compile("org.jetbrains.kotlin:kotlin-stdlib-jre8:${kotlinVersion}") compile("io.jsonwebtoken:jjwt:0.7.0") testCompile('com.h2database:h2') testCompile('org.springframework.security:spring-security-test') testCompile('org.springframework.boot:spring-boot-starter-test') testCompile('io.projectreactor:reactor-test') } 

and that worries me because of warn in build (and fails in tests as i guess):

w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath: /home/travis/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.10/19bc012f8c4cd6b705bd6512263777cc19bcf259/kotlin-reflect-1.2.10.jar (version 1.2) /home/travis/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jre8/1.2.10/71c98c16b4bed3f754c6c398f9da8300ecb0a669/kotlin-stdlib-jre8-1.2.10.jar (version 1.2) /home/travis/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jre7/1.1.61/59dfce93b1995717338435dd974884007d8e8474/kotlin-stdlib-jre7-1.1.61.jar (version 1.1) /home/travis/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.1.61/fa7813a26c548c9c412dd2d42fb466cfcd8dcf3c/kotlin-stdlib-1.1.61.jar (version 1.1) w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath or use '-Xskip-runtime-version-check' to suppress this warning :spring-boot-server:compileTestJava NO-SOURCE :spring-boot-server:processTestResources :spring-boot-server:testClasses :spring-boot-server:testPicked up _JAVA_OPTIONS: -Xmx2048m -Xms512m com.witkups.carsharing.CarSharingApplicationTests > contextLoads FAILED java.lang.IllegalStateException Caused by: java.lang.IllegalStateException Caused by: java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException 1 test completed, 1 failed :spring-boot-server:test FAILED 

test:

package com.witkups.carsharing import org.junit.Test import org.junit.runner.RunWith import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.junit4.SpringRunner @RunWith(SpringRunner::class) @SpringBootTest class CarSharingApplicationTests { @Test fun contextLoads() { } } 

Any help will be appreciated :) PS: JDK 8


Solution

I have added following lines in build.gradle script:

compile("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}") compile("org.jetbrains.kotlin:kotlin-stdlib-jre8:${kotlinVersion}") compile("org.jetbrains.kotlin:kotlin-stdlib-jre7:${kotlinVersion}") compile("org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}") 

and works like a charm. Tests stopped failing when i replaced

@RunWith(SpringRunner::class) 

with

@ExtendWith(SpringExtension::class) 
1
  • How was your IntelliJ project created? Have you done as suggested, and seen dependencyInsight for Kotlin? Have you looked at module and library definitions? I suspect it's because you used the Idea plugin for Gradle to generate the project, and it had an older version of Kotlin added to the library path. I'd recommend import Gradle projects directly into IntelliJ and don't use the idea plugin for Gradle anymore. Commented Dec 26, 2017 at 3:56

2 Answers 2

3

One of your dependencies itself depends on kotlin-stdlib-jre7. So far as Gradle knows, kotlin-stdlib-jre7 and kotlin-stdlib-jre8 are completely unrelated, so it places both on the classpath, which leads to the condlict.

Try ./gradlew dependencyInsight kotlin-stdlib-jre7 to see where the dependency is coming from and exclude it. E.g. if it turns out to be jackson-module-kotlin, write

compile('com.fasterxml.jackson.module:jackson-module-kotlin:2.9.2') { exclude group: "org.jetbrains.kotlin" } 

See also https://docs.gradle.org/current/userguide/dependency_management.html#sub:version_conflicts.

Sign up to request clarification or add additional context in comments.

3 Comments

I just added deps to actual versions of those libs (1.2.1) because even kotlin-stdlib-jre8 depends on jre7... but test still fails. Nevertheless thank you :)
@azbesciak. Did this solve your problem? If not, then it shouldn't be the accepted answer. If it did, please update something to make it clear how this solved your problem to help others.
It helped me to solve problem with IDE problem, not with tests.. but it is other story as i suppose, maybe connnected with github.com/waicool20/KAGA/issues/27 as i think now looking at my local building
3

According to What's New in Kotlin 1.2 there are new dependencies for Java 7 and 8, e. g. kotlin-stdlib-jdk8 instead of the old kotlin-stdlib-jre8. Using this auto-fixes the transient import for kotlin-stdlib-jdk7 but unfortunately not for kotlin-stdlib. It is still 1.1.61.

./gradlew dependencyInsight --dependency kotlin-stdlib > Task :dependencyInsight org.jetbrains.kotlin:kotlin-stdlib:1.1.61 (selected by rule) org.jetbrains.kotlin:kotlin-stdlib:1.2.10 -> 1.1.61 +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.10 | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.10 | \--- compileClasspath \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.10 (*) org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.10 \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.10 \--- compileClasspath org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.10 (selected by rule) org.jetbrains.kotlin:kotlin-stdlib-jdk8: -> 1.2.10 \--- compileClasspath (*) - dependencies omitted (listed previously) 

You could additionally declare kotlin-stdlib with an explicit version to fix the warning.

compile("org.jetbrains.kotlin:kotlin-stdlib:1.2.10") compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8") 

3 Comments

@Azbesciak please note the small difference (jdk vs. jre). You didn't mention this and I thought, this could help someone.
Always better to say it explicite :) You are right, i didn't.
I did some further research. The old dependency version comes from the plugin 'io.spring.dependency-management'. If I temporarily remove the plugin (which isn't a complete build config), I get the correct version for 'org.jetbrains.kotlin:kotlin-stdlib' without the need to define it explicitly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.