kotlinc
Compile Kotlin source code to bytecode
TLDR
Start a REPL (interactive shell)
Compile a Kotlin file
Compile several Kotlin files
Execute a specific Kotlin Script file
Compile a Kotlin file into a self contained jar file with the Kotlin runtime library included
SYNOPSIS
kotlinc options source_files
PARAMETERS
-d output_directory or jar_file
Specifies the output directory for the compiled .class files, or the name of the JAR file to create.
-classpath path or -cp path
Specifies the classpath for resolving dependencies during compilation.
-include-runtime
Includes the Kotlin runtime library in the output JAR file, creating an executable JAR.
-nowarn
Suppresses all compiler warnings.
-verbose
Enables verbose output during compilation.
-version
Prints the Kotlin compiler version.
-help
Prints a list of available compiler options.
-jvm-target version
Specifies the target JVM version for the generated bytecode (e.g., 1.6, 1.8, 11).
-module module_name
Creates a .kotlin_module file that describes the structure of the module.
DESCRIPTION
The kotlinc command is the command-line compiler for the Kotlin programming language. It allows you to compile Kotlin source files (.kt) into Java bytecode (.class files) or, with the Kotlin/Native compiler, into native binaries. It's a crucial tool for Kotlin developers working in a terminal environment, automating build processes, and integrating Kotlin code into larger Java or native projects.
kotlinc provides various options to control the compilation process, including setting the classpath, specifying output directories, enabling or disabling language features, and generating debugging information. Understanding these options is essential for efficiently managing Kotlin projects and creating optimized and well-behaved applications. The command can also compile multiple Kotlin files together, resolving dependencies automatically during compilation.
ERROR HANDLING
The compiler reports errors and warnings during the compilation process. It's crucial to address these issues to ensure code correctness and stability. Error messages often provide helpful context and suggestions for resolving the problems. Make sure you pay attention to deprecated functions or invalid usages of code.
HISTORY
The kotlinc command was developed as part of the Kotlin programming language project by JetBrains. Kotlin was first publicly announced in 2011, with version 1.0 released in 2016. kotlinc has evolved alongside the Kotlin language, adding new features and improvements to the compilation process. It is now a mature and widely used compiler, supporting a wide range of platforms and development environments.