Welcome to this new edition of One Framework a Day keeps the Boredom Away. In this series I will show you how to deploy a particular framework on Clever Cloud every day until I want to go back to boredom. Today it's about a bunch of interesting technologies: Kotlin, Spring 5 and MongoDB.

If you want to tag along, make sure you have git, a Clever Cloud account and that you have installed our CLI Clever-Tools.

What is Kotlin, Spring 5 and Reactive MongoDB?

This time we get to talk about all these things in one post because of a code sample I found. Someone on twitter asked us if Kotlin code could be deployed on Clever Cloud. The answer is yes. You can deploy anything that can be packaged as a Jar or War. So that means Kotlin, but also Ceylon, Clojure, Groovy, Scala and many more. So what is Kotlin?

Kotlin is a statically-typed programming language that runs on the Java virtual machine and also can be compiled to JavaScript source code or use the LLVM compiler infrastructure.

It's also worth noting that it can target native environment beyond the JVM. So it can be used to write iOS app for instance. This post on multiplatform native developement with Kotlin will give you a better idea of the many things you can do.

Anway I looked for a Kotlin sample online and I found the traditional Pet Clinic sample written in Kotlin with Spring 5 and Reactive MongoDB. Which is nice because Spring 5 is all about being reactive. And Kotlin is a great fit for that because of its Lambdas support. But we are not going to look at the code, we are going to look at how to deploy this Kotlin/MongoDB project on Clever Cloud.

Setup

Here are the steps you need to go through to deploy this application:

  • Clone the project: git clone https://github.com/ssouris/petclinic-spring5-reactive
  • Get in the project: cd petclinic-spring5-reactive
  • Create our PostgreMongoDB add-on: clever addon create mongodb-addon --plan peanut petClinicMongo
  • Create our application: clever create --type gradle petClinic
  • Link our MongoDb add-on: clever service link-addon petClinicMongo

Setup the necessary environment variables for configuration:

clever env set GRADLE_DEPLOY_GOAL bootRun
clever env set SPRING_DATA_MONGODB_URI `clever env | awk  -F = '/MONGODB_ADDON_URI/ { print $2}'`

Here we start by specifying which Gradle goal to run. This goal compiles and runs the application. Then we configured the MongoDB connection.

Deploy

To deploy your application, run clever deploy then clever open. You should see the logs of your application being ran successfuly then have the website open in your default web browser. And as you can see your Kotlin project is up and running and talking to a MongoDB database the reactive way.

blog comments powered by Disqus