Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Kotlin in Grails?

Some basic facts that lead me to this question:

  • Groovy has complete Java interoperability
  • Kotlin has complete Java interoperability
  • Kotlin also compiles down to Java

Is it therefore possible to write Kotlin code in a Grails application?

I've worked quite a bit with Grails 2.x, and recently at a new job I have been working with Kotlin, Spring, and Struts. I really like the null-safety and type inference features of Kotlin, and the functional programming features of Kotlin feel much more natural and easy to use than in Groovy (this last part is pure opinion).

Is it possible to use Grails to handle things like:

  • ORM
  • Mapping requests to controllers/actions
  • JSP/GSP view parsing/rendering

but use Kotlin to write the actual logic of the domain classes, controller actions, services, object factories, etc.

Probably not likely, because I'm guessing that some of the core functionality of Grails is made possible by dynamic typing, but maybe it could be possible through either a Gradle plugin or a direct Grails plugin.

I like the extreme simplicity provided by the convention-over-configuration paradigm of Grails, but I much prefer the static typing and type inference of Kotlin.

If I could write business logic in Kotlin in a Grails environment, that, to me, would be the ultimate web application framework!

like image 232
Mat Jones Avatar asked Jul 14 '17 00:07

Mat Jones


1 Answers

Is it therefore possible to write Kotlin code in a Grails application?

Definitely. You can use any JVM language from a Grails app. I built a proof of concept with Kotlin in Grails and everything worked just as one would hope: https://github.com/jeffbrown/langdemo

like image 170
Jeff Scott Brown Avatar answered Oct 10 '22 09:10

Jeff Scott Brown