← 返回命令列表

Linux command

kotlinc 命令

网络

需要网络或远程资源。

常用示例

Compile Kotlin file

kotlinc [file.kt] -include-runtime -d [output.jar]

Compile to class files

kotlinc [file.kt] -d [output_dir]

Compile multiple files

kotlinc [file1.kt] [file2.kt] -d [output.jar]

Add classpath

kotlinc -cp [lib.jar] [file.kt] -d [output.jar]

Compile with JVM target

kotlinc -jvm-target [17] [file.kt] -d [output.jar]

说明

kotlinc is the command-line Kotlin compiler that translates Kotlin source files (.kt) into JVM bytecode. It can produce either standalone JAR files with the Kotlin runtime bundled via the `-include-runtime` flag, or output class files to a directory for integration with existing build pipelines. The compiler supports full interoperability with Java, allowing Kotlin code to call Java libraries and vice versa. It accepts a target JVM version through the `-jvm-target` option, supports adding external dependencies via the classpath, and can compile multiple source files together. For larger projects, build tools like Gradle or Maven are typically preferred, but kotlinc is useful for quick compilation tasks, learning, and scripting workflows.

参数

-d _OUTPUT_
Output JAR or directory.
-include-runtime
Include Kotlin runtime.
-cp _PATH_
Classpath.
-jvm-target _VERSION_
Target JVM version.
-no-stdlib
Don't automatically include kotlin-stdlib.jar and kotlin-reflect.jar in the classpath.
-no-reflect
Don't automatically include kotlin-reflect.jar in the classpath.
-jdk-home _path_
Use a custom JDK home directory instead of the default JAVA_HOME.
-language-version _version_
Compile against the specified Kotlin language version (e.g. `2.0`).
-script
Evaluate a Kotlin script file (.kts).
-nowarn
Suppress all compiler warnings.
-Werror
Treat all warnings as compilation errors.
-verbose
Enable verbose logging output with compilation details.
-version
Display the compiler version.
-help, -h
Display usage information.

FAQ

What is the kotlinc command used for?

kotlinc is the command-line Kotlin compiler that translates Kotlin source files (.kt) into JVM bytecode. It can produce either standalone JAR files with the Kotlin runtime bundled via the `-include-runtime` flag, or output class files to a directory for integration with existing build pipelines. The compiler supports full interoperability with Java, allowing Kotlin code to call Java libraries and vice versa. It accepts a target JVM version through the `-jvm-target` option, supports adding external dependencies via the classpath, and can compile multiple source files together. For larger projects, build tools like Gradle or Maven are typically preferred, but kotlinc is useful for quick compilation tasks, learning, and scripting workflows.

How do I run a basic kotlinc example?

Run `kotlinc [file.kt] -include-runtime -d [output.jar]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -d _OUTPUT_ do in kotlinc?

Output JAR or directory.