kotlin

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.

Weiterlesen

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 .

Weiterlesen

Functional Kotlin starting from Java

This post is about the transition from Kotlin sourcecode that looks like java code to code that uses the functional Kotlin constructs. Starting up I will write about a completely made up class here but I experienced that you can do that with almost any class in the entire codebase. Inspiration from the daily programmer: word funnel Starting with Java We start with the java implementation of the word funnel puzzle mentioned above

Weiterlesen

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.

Weiterlesen

Null pointer in Kotlin

The Null Pointer Problem Java devs have struggled withe the Problem of the NullPointerException for years and more years to come. It has been named the ‘Billion Dollar Mistake’ and it probably did cost something ranging in this number. Kotlin is coming up with a pretty neat solutions to this old Problem. It does not prevent NullPonterExceptions completely but it warns you every time you are about to introduce code that could lend to this technical debt.

Weiterlesen

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.

Weiterlesen

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.

Weiterlesen

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:

Weiterlesen

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.

Weiterlesen

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.

Weiterlesen