Rest Microframework Jooby

In this post I want to introduce the Jobby microframework for Kotlin and Java. They don’t have a nice getting started site yet so I decided to make a quick write up. We will write a small rest service in Kotlin for managing persons. This web service is going to take up under 30 lines of code. Starting up We will use Gradle to build our rest application. mkdir kotlin_jooby cd kotlin_jooby gradle init --dsl kotlin src/build.
Read more...

Build a simple calculator with TornadoFX

TornadoFX is a ui framework for Kotlin on top of JavaFX. It leverages the functional capabilities of Kotlin to create an easy to use ui framework with JavaFX as stable backbone. In this tutorial we will create a simple calculator that will allow us to add, subtract and multiply integers. Setting up For this tutorial we will use gradle with kotlin dsl to build the test application. mkdir kotlin_tornado cd kotlin_tornado gradle init --dsl kotlin The gradle build file is quiet extensive but I think the comments are explaining enough.
Read more...

Tests with Kotlin

Introduction Tests are important for software development to ensure qualitz and maintainability. Tests in Kotlin can be done in a very similiar way as in Java. The basic concepts like unittests, integrationtests, mocking, dependency injection, etc can also be applied to Kotlin code. I will use the framework JUnit 5 throughout this tutorial. It is the Java test framework and fully compatible with Kotlin. The first test Kotlin can use the same Annotations Java uses so our first test looks pretty similiar:
Read more...

Adding parameters to a Gradle plugin

Introduction Last time I wrote about the basic setup of a Gradle plugin in Kotlin(Writing a Gradle plugin with Kotlin). This time we want to add some parameters to this plugin to make it more generic. Basics Gradle is a build automation tool from the java ecosystem. It has a lot of plugins for various use cases. Buildfiles are describedin Groovy as default but Gradle recently added the possibility to also write build scripts in a Kotlin DSL.
Read more...

Writing a Gradle Plugin with Kotlin

Motivation I recently started a project for making migrations for Keycloak possible in a liquibase-like style. To be able to invoke this migrations from gradle I had to write a gradle plugin. I didn’t find a good ressource how to do so, so I decided to make a quick write up. Basics Gradle is a build automation tool from the java ecosystem. It has a lot of plugins for various use cases.
Read more...

Migrate Keycloak like SQL

What is Keycloak? Keycloak is an authorization provider that supports various authentication protocols. You can use it with OAuth, LDAP, Kerberos, etc. It is based on the free WildFly application server. Why is migration a Problem? You can manage Keycloak through an admin ui, or with the provided REST-Api. Keycloak also supports realm export and import. So we could just track keycloak changes through the export file. The difficulty of this approach is, that the realm export has to be done before starting the Keycloak server.
Read more...

Dependency Injection with Koin

What is dependency injection Dependency injection is a technique to organize dependencies of services at runtime. If you have a really large application you may have encountered the problem of passing some objects down the whole stack and maybe using singletons and static method to overcome this. But these are hard to substitute in Tests. Though to avoid this we let a framework organize these dependency issues for us. See Wikipedia.
Read more...

Operator Overloading in Kotlin

What is operator overloading? Operator overloading has its root in the language C++. It means, that you can define the behavior if an operator (e.g. +, -, *, …) is applied to your type. (Wikipedia) In C++ this looks like the following. Given we have a class Vector containing a x and a y field as coordinates. We can define the operator plus + as follows: Vector operator + (Vector const &obj) { Vector res; res.
Read more...

Minimal Webservice with data classes and spring boot data rest

Spring Boot Data REST and Kotlin data classes enable an very code efficient way to provide CRUD Interfaces. We will create a small webservice for managing persons. Setting up For this tutorial we will use gradle with kotlin dsl to build the application. mkdir spring_data_class cd spring_data_class gradle init --dsl kotlin 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 plugins { kotlin("jvm") version "1.
Read more...

Part 2: Accessing the webservice with KTor client

In the last post Part 1 we created a simple webservice for organising tasks. This time we will access this service using the KTor client features. Setting up For this tutorial we will use gradle with kotlin dsl to build the application. mkdir kotlin_ktor_client cd kotlin_ktor_client gradle init --dsl kotlin plugins { application kotlin("jvm") version "1.3.0" } application { mainClassName = "client.ClientKt" } dependencies { compile(kotlin("stdlib")) compile("io.ktor:ktor-client-core:1.0.0") compile("io.ktor:ktor-client-apache:1.0.0") } repositories { mavenCentral() jcenter() } // We need this task to package the client into a jar task("packageClient", type = Jar::class) { from(configurations.
Read more...