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.jarCommon 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-runtimeproduces a standalone JAR you can run with plainjava -jar.- Set
-jvm-targetto match the JDK that will run the output. - Most CI failures are "unresolved reference" from a missing classpath entry.
Related guides
javac Command: Compile Java in CIjavac is the Java compiler. Reference for -d, -cp/-classpath, --release, -source/-target, -Xlint, and the pac…
scalac Command: Compile Scala in CIscalac is the Scala compiler. Reference for -d, -classpath, -deprecation, -Xfatal-warnings, -release, and the…
gradle Command: Build JVM Projects in CIgradle is the JVM build tool. Reference for build, test, --no-daemon, --build-cache, -x, --stacktrace, and th…