SQL DSL JOOQ

In this post I want to introduce the JOOQ sql domain specific language (DSL) for Kotlin and Java.

It is free for open source databases and we will use postgresql in this tutorial.

We will write a small app to manage todolists in Kotlin.

I will not explain how to setup a postgresql database but there are a lot of tutorials available for several operating systems.

Create the database

At first we need to connect to our postgres database, add a user and create a database.

Continue reading

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:

Continue reading

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.

Continue reading

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 

build.gradle.kts

plugins {
    kotlin("jvm") version "1.3.0"
    // to start our server directly from gradle
    application
}
dependencies {
    compile(kotlin("stdlib"))

    compile("org.jooby:jooby:1.6.0")
    // Add kotlin language support
    compile("org.jooby:jooby-lang-kotlin:1.6.0")

    // We need a server runtime to contain our application
    runtime("org.jooby:jooby-netty:1.6.0")
}

repositories {
    mavenCentral()
}

application {
    mainClassName = "de.klg71.joobytest.MainKt"
}

Continue reading