Help using Kotlin in a Scala/Java IntelliJ project?


#1

Hi,

I have a project (a web app) that is a mix of Java and Scala code. I use IntelliJ and it works great - everything gets compiled and the classes can call each other. Can I throw Kotlin into the mix? I tried it in a sample project and it doesn’t seem to work 100%.

What I did: installed the Kotlin plugin, started a new project and chose a Scala module (that’s what my real project is like). I added a Java file, Scala file, and Kotlin file. They can all call each other, except Kotlin can’t call Scala.  I get this…

fun main(args: Array<String>) {

  println("In kotlin main")

  val jc = com.foo.JavaClass1()

  jc.foo()

  val sc = com.foo.ScalaClass1()  // Error:(3, 19) Kotlin: Unresolved reference: ScalaClass1

  sc.foo()

}

Anything suggestions?  (IntelliJ 13.1.4, Scala plugin 0.38.441, Kotlin 0.8.11)

thanks,
Rob


#2

Hello, I'm afraid having kotlin and scala in the mix is not something we tested and it's not in our priority list to support mixed scala/kotlin projects.

I believe using scala libraries should work and you can use them from kotlin like you can from java. I think you can build such a multilingual module provided it is possible to compile kotlin sources after scala sources and before java sources.

But IDE support is another story. AFAIK, this is the first request for supporting scala/kotlin mixed projects and I doubt that would be a common usecase (why would you need kotlin if you have scala and vice versa).

You can file an issue to our tracker and see if there are other people who are interested in this kind of usecase.

Pavel


#3

Okay, thanks. I can probably get it to work as you described, compiling in specific order, or using Java as a go-between.

I agree it shouldn’t be a priority. I just wanted to know my options for experimenting with Kotlin in an older codebase, where Scala and Java can’t be removed easily.

Rob


#4

BTW, can Scala call Kotlin there?


#5

abreslav wrote:

BTW, can Scala call Kotlin there?

Yes, it can. Of the 6 possible tests, the only one that didn’t work was Kotlin --> Scala.  So I can go Kotlin --> Java --> Scala if needed.