Bootique v2 Kotlin Documentation

1. Overview

bootique-kotlin contains following modules:

  1. Kotlin APIs and extensions for Bootique;

  2. Kotlin Script Configuration Module;

  3. Configuration and Extensions for Bootique Modules;

  4. JacksonService which provides ObjectMapper with enabled KotlinModule.

2. TL;DR;

  • Use KotlinBootique instead of Bootique;

  • Use KotlinModule instead of Module, you can use KotlinModule with ConfigModule (just inherit both);

  • Use KotlinBQModuleProvider instead of BQModuleProvider;

  • Use extensions defined in Extensions.kt;

  • Use bootique-kotlin-configuration module to benefit from configuration written in Kotlin.

  • Use bootique-kotlin-jackson to get ObjectMapper with KotlinModule.

3. Getting started

Kotlin 1.4.10 used in project.

Latest stable version: Maven Central

Add dependency on needed parts in your build.gradle, or pom.xml:

// Kotlin Extensions for Bootique

// Kotlin Configuration Module

// Kotlin Configuration Module

// Kotlin Configuration and Extensions for Jetty. Also this adds dependency to bootique-jetty module.

// Kotlin Configuration and Extensions for Logback. Also this adds dependency to bootique-logback module.

// Kotlin Configuration and Extensions for $moduleName$. Also this adds dependency to bootique-$moduleName$ module.

bootique-kotlin modules doesn’t include kotlin-stdlib-jdk8, or any other core kotlin libraries, since you can use newer kotlin version and usually you already have kotlin-stdlib-jdk8 in runtime. So there are list of additional dependencies for different bootique-kotlin modules:



If you use different kotlin version, it’s much simpler to include these libraries with proper version, instead of excluding library version of them and then including again.

If you’d like to use snapshot versions, you have to add bootique snapshot repository:

For example in gradle it can be done this way:

repositories {
    maven { url = uri("") }

And then use snapshot version: 2.0.B1-SNAPSHOT.

4. Bootique

4.1. KotlinBootique

bootique-kotlin provides replacement for Bootique class - KotlinBootique:

fun main(args: Array<String>) {

So no need for extensions for Bootique class, KotlinBootique provides best experience for developing Bootique apps with Kotlin.

4.2. KotlinBQModuleProvider

KotlinBQModuleProvider - interface to implement in Bootique Kotlin application instead of BQModuleProvider.

class ApplicationModuleProvider : KotlinBQModuleProvider {
    override val module = ApplicationModule()
    override val overrides = listOf(BQCoreModule::class)
    override val dependencies = listOf(KotlinConfigModule::class)

You can see how declarative become module provider.

4.3. ConfigurationFactory

// Using Java Api
configurationFactory.config(, "sample")

// With Extension
configurationFactory.config(SampleFactory::class, "sample")

// With Extension, reified generics

// Type Inference
fun createAppConfiguration(configurationFactory: ConfigurationFactory): SampleFactory {
    return configurationFactory.config/* No Type Here */(configPrefix)

4.4. Adding command

Straightforward and easy to use extension for contributing commands.


4.5. Default command

Also extension for setDefaultCommand available.


4.6. Bootique DI

4.6.1. KotlinModule

bootique-kotlin introduces new module interface to use with kotlin: KotlinModule

class ApplicationModule : KotlinModule {
    override fun configure(binder: KotlinBinder) {

4.6.2. Extensions

There are few functions to help work with TypeLiteral and Key.

// TypeLiteral

// Key

5. Configuration Module

Using Kotlin Script for a configuration is really simple:

  1. Create script

  2. Override ConfigurationFactory

5.1. Using Kotlin Script file

Configuration with Kotlin can be defined in Kotlin Script file:

import io.bootique.kotlin.config.modules.httpConnector
import io.bootique.kotlin.config.modules.jetty

jetty {
    httpConnector {
        port = 4242
        host = ""

5.2. Enable Kotlin Script Configuration

Enable Kotlin Script Configuration in Bootique with extension:

fun main(args: Array<String>) {
        .withKotlinConfig() // Extension function

Using BQModuleProvider:

fun main(args: Array<String>) {

You can pass this file as always to bootique:

./bin/application --server

It’s even support multiple files (each file contains map of configs):

./bin/application --server

That’s it! You get autocomplete in IDE, and code for a configuration!

6. Bootique Jetty

Define empty config:

jetty {


Use autocompletion to define configuration.

Use httpConnector/httpsConnector extensions to define connectors:

jetty {
    httpConnector {
        port = 4242
        host = ""
        responseHeaderSize = 42
        requestHeaderSize = 13

7. Bootique Logback

Define logback configuration:

addConfig("log", logbackContextFactory(
    logFormat = "[%d{dd/MMM/yyyy:HH:mm:ss}] %t %-5p %c{1}: %m%n",
    useLogbackConfig = false,
    debugLogback = false,
    level = LogbackLevel.warn,
    loggers = mapOf(
        logger(LogbackModuleTest::class, LogbackLevel.error),
        logger("TestLogger", LogbackLevel.trace)
    appenders = listOf(
            logFormat = "[%d{dd/MMM/yyyy:HH:mm:ss}] %t %-5p %c{1}: %m%n",
            target = ConsoleTarget.stderr
        fileAppender(logFormat, "abc", timeBasedPolicy(
            fileNamePattern = "Abc_%d",
            totalSize = "2m",
            historySize = 1

Use function for retrieving logger for class:

val logger = logger<SomeService>()

Or if class is generic:

val logger = logger<SomeService<*>>()

8. Bootique Undertow

Define undertow configuration:

addConfig("undertow", undertowFactory(
    httpListeners = listOf(
        httpListener(1337, "")
    workerThreads = 42