1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

kotlinでjsonを扱おうとしたら警告が...

Last updated at Posted at 2018-10-16

概要

書籍を参考にkotlinを学習中していると、躓いたのでメモする

jacksonの追加

gradleでjacksonというjsonライブラリを追加するように指示があったので、とりあえずコピペしてみる。

gradle.build
plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.2.71'
}

version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    compile 'org.slf4j:slf4j-log4j12:1.7.21'
    compile 'com.sparkjava:spark-core:2.6.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.8.8.1'      <- ここを追加
    compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.8.8' <- ここを追加
}

すると、以下の警告が表示されるようになり、どうも不安定になる。

Warning:Kotlin: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    /Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.2.71/5470d1f7/kotlin-stdlib-jdk8-1.2.71.jar (version 1.2)
    /Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.2.71/4ce93f53/kotlin-stdlib-jdk7-1.2.71.jar (version 1.2)
    /Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.1.1/e68cf130c/kotlin-reflect-1.1.1.jar (version 1.1)
    /Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.71/d9717625b/kotlin-stdlib-1.2.71.jar (version 1.2)
    /Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.2.71/ba18cc/kotlin-stdlib-common-1.2.71.jar (version 1.2)
Warning:Kotlin: Consider providing an explicit dependency on kotlin-reflect 1.2 to prevent strange errors
Warning:Kotlin: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath

どうやら1.1系と1.2系が混ざっているという警告のようだ。
調べてみると下記記述がヒットする。
https://github.com/FasterXML/jackson-module-kotlin/issues/97

I upgraded to kotlin 1.2.0 and fasterxml 2.9.2 and it seems to be working

そこで、2.8.x系だから良くないのかと、2.9.x系の最新版「2.9.6」に変更する。

gradle.build
dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    compile 'org.slf4j:slf4j-log4j12:1.7.21'
    compile 'com.sparkjava:spark-core:2.6.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.9.6'
    compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.6'
}

警告が表示されなくなる。
buildが失敗したりと不安定だったので、これで正常に動くようになればいいですが...

参考サイト

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?