Skip to content
Latchkey

kotlinc Command: Compile Kotlin in CI

kotlinc compiles Kotlin source into JVM class files or a runnable JAR.

kotlinc is the standalone Kotlin compiler. Most projects compile Kotlin through Gradle, but kotlinc appears in scripts and minimal CI images for small tools and scratch builds. Its flags mirror javac with Kotlin-specific additions.

Common flags

  • -include-runtime - bundle the Kotlin runtime into the output JAR
  • -d OUT - output directory or .jar file name
  • -classpath / -cp PATH - dependency class path
  • -jvm-target 17 - target JVM bytecode version
  • -Werror - treat warnings as errors
  • -language-version 2.0 - pin the Kotlin language version
  • -opt-in=kotlin.RequiresOptIn - opt into experimental APIs

Example in CI

Compile a Kotlin source tree into a self-contained runnable JAR:

shell
kotlinc src -include-runtime -jvm-target 17 -d build/app.jar

Common errors in CI

  • error: unresolved reference: X - missing import or dependency on the classpath
  • error: incompatible types - type mismatch the compiler cannot reconcile
  • warning: 'jvmTarget' was deprecated - align with the toolchain JDK
  • error: this class file version is not supported - JDK older than -jvm-target

Key takeaways

  • -include-runtime produces a standalone JAR you can run with plain java -jar.
  • Set -jvm-target to match the JDK that will run the output.
  • Most CI failures are "unresolved reference" from a missing classpath entry.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →