Kotlin multiplatform JVM type mismatch in IntelliJ

拟墨画扇 提交于 2019-12-11 04:49:11

问题


I have a project which contains the following modules:

  • common
  • common-js
  • common-jvm
  • backend
  • web

The idea is that I put my shared (kotlin) code (mainly models) in common, which can be used in both the kotlin driven backend and the javascript driven webapp using the recently introduced multiplatform support. To do this, I created a new multiplatform application in Intellij, and added the backend and web modules to it.

An example class in the common module:

data class Show(
    val id: Long,
    val type: ShowType,
    val title: String,
    var description: String? = null
)

The backend is a simple spring boot application. It has a dependency on the common-jvm project:

compile project(":common-jvm")

Now when I run gradle bootRun, the application starts and works fine. However, when I try to run the same application using IntelliJ, I get errors like:

Error:(68, 26) Kotlin: Type mismatch: inferred type is kotlin.Long but java.lang.Long was expected
Error:(68, 65) Kotlin: Type mismatch: inferred type is kotlin.String! but java.lang.String was expected

On this line, I try to create an instance of the Show model using data from a json source:

val movie = Show(json.get(id).asLong(), ShowType.MOVIE, json.get(movieTitle).asText())

I am using Kotlin 1.2.10 and spring boot 1.5.9.RELEASE.

Anybody who knows what causes this and how it can be solved? I tried putting -Xmulti-platform in the additional command line parameters in the project structures for the backend module, but this did not work either.


回答1:


You need to delegate build/run actions to Gradle, since building multiplatform projects with IDEA is not supported at this moment.



来源:https://stackoverflow.com/questions/48066754/kotlin-multiplatform-jvm-type-mismatch-in-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!