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…
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.
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.
There are. Sorry for long post, but I’ll try to explain why it is not just a caprice.
The case is rather typical. We have thosands lines of working code in scala, many backend projects. And we still continue to start new scala projects as there is yet no alternative to scala’s anorm for database and until recently there was nothing suitable as a small-scaled high efficiency web server. Especially as we need one without coroutines that for few performance increase (which never was a problem with scala) give us x3 development costs. Still, we love kotlin and write more and more stuff in it, manly, for application software, and we’d gladly share our newer kotlin stuff. Which is, frankly, close to impossible: setting up and maintainig sbt + gradle modular project is usuallymore expensive than rewriting from kotlin to scala. Which is, in turn more expenses on supporting 2 versions of the same code. Modular projects with scala+kotlin It is not at all documented, all we know that in theory it could be done but even IJ doesn’t know how
Moreover, this lack of interoperability we mistakenly had assumed we’ll have, makes us reconsider using kotlin in clients: no DRY, no gain, just pain of limitless rewriting between similar languages. Especially that language-level await makes typescript less pain in js apps world than kotlin.js or scala.js.
We need interoperability. With it, we might happily migrate to kotlin. Without it, we are bound to remain in scala, develop more and more in scala, and probablty stop using kotlin for applciations, as “just for adnroid” is not enough, java FX is a buggy slow monster, and there are no more reasons to maintain it. We could get more for less kissing kotlin goodbye and switching to typescript. And leave kotlin to hobby projects (where it certainly won’t survive python’s competition).
Personally, as a programmer, I’d be glad to try to use kotlin despite of all this, but being a CTO I can’t accept such a risky strategy in my projects and teams. Pity on that.