All posts

Kotlin Application Deployment Checklist

Complete Kotlin deployment checklist for JVM applications covering Gradle builds, JVM tuning, health checks, and container configuration.

Kotlin Application Deployment Checklist

Kotlin JVM applications share many deployment concerns with Java but have unique considerations. Here's your production checklist.

Build Configuration

// build.gradle.kts
tasks.withType<Jar> {
    manifest {
        attributes["Main-Class"] = "com.example.ApplicationKt"
    }
}

tasks.register<Jar>("fatJar") {
    archiveClassifier.set("all")
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
    with(tasks.jar.get())
}
  • [ ] Fat JAR or layered Docker build configured
  • [ ] ProGuard/R8 configured for size optimization (if applicable)
  • [ ] Kotlin version matches all dependencies

JVM Tuning

java -Xms512m -Xmx2g \
  -XX:+UseG1GC \
  -XX:MaxGCPauseMillis=200 \
  -XX:+UseContainerSupport \
  -jar app-all.jar
  • [ ] Heap size configured (-Xms and -Xmx)
  • [ ] Container-aware JVM flags enabled
  • [ ] GC algorithm selected for workload type

Coroutine Configuration

// Use appropriate dispatchers
val dbDispatcher = Dispatchers.IO.limitedParallelism(20)
val cpuDispatcher = Dispatchers.Default

// Install exception handler
val handler = CoroutineExceptionHandler { _, exception ->
    logger.error("Unhandled coroutine exception", exception)
}

val scope = CoroutineScope(SupervisorJob() + handler)
  • [ ] Coroutine exception handlers installed
  • [ ] Dispatchers configured for workload types
  • [ ] SupervisorJob used for independent child coroutines

Health and Monitoring

routing {
    get("/health") {
        val dbHealthy = checkDatabase()
        val status = if (dbHealthy) HttpStatusCode.OK else HttpStatusCode.ServiceUnavailable
        call.respond(status, mapOf("status" to if (dbHealthy) "healthy" else "degraded"))
    }
}
  • [ ] Health endpoint checks all dependencies
  • [ ] Structured logging with kotlin-logging
  • [ ] Error tracking with Bugsly for exception visibility
  • [ ] Metrics endpoint for monitoring

Container Setup

FROM eclipse-temurin:21-jre-alpine
COPY build/libs/app-all.jar /app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]
  • [ ] Minimal base image (JRE, not JDK)
  • [ ] Non-root user configured
  • [ ] Graceful shutdown handles SIGTERM

Try Bugsly Free

AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.

Get Started Free