# Kotlin compiler options Each release of Kotlin includes compilers for the supported targets: JVM, JavaScript, and native binaries for [supported platforms](native-overview.html#target-platforms). These compilers are used by: * The IDE, when you click the Compile or Run button for your Kotlin project. * Gradle, when you call `gradle build` in a console or in the IDE. * Maven, when you call `mvn compile` or `mvn test-compile` in a console or in the IDE. You can also run Kotlin compilers manually from the command line as described in the [Working with command-line compiler](command-line.html) tutorial. ## Compiler options Kotlin compilers have a number of options for tailoring the compiling process. Compiler options for different targets are listed on this page together with a description of each one. There are several ways to set the compiler options and their values (compiler arguments): * In IntelliJ IDEA, write in the compiler arguments in the Additional command line parameters text box in Settings/Preferences | Build, Execution, Deployment | Compiler | Kotlin Compiler. * If you're using Gradle, specify the compiler arguments in the `compilerOptions` property of the Kotlin compilation task. For details, see [Gradle compiler options](gradle-compiler-options.html#how-to-define-options). * If you're using Maven, specify the compiler arguments in the `` element of the Maven plugin node. For details, see [Maven](maven-kotlin-compiler.html#specify-compiler-options). * If you run a command-line compiler, add the compiler arguments directly to the utility call or write them into an [argfile](#argfile). For example: ```BASH $ kotlinc hello.kt -include-runtime -d hello.jar ``` Note: On Windows, when you pass compiler arguments that contain delimiter characters (whitespace, `=`, `;`, `,`), surround these arguments with double quotes (`"`). ``` $ kotlinc.bat hello.kt -include-runtime -d "My Folder\hello.jar" ``` ## Schema for compiler options A common schema for all compiler options is published under [org.jetbrains.kotlin:kotlin-compiler-arguments-description](https://central.sonatype.com/artifact/org.jetbrains.kotlin/kotlin-compiler-arguments-description) as a JAR artifact. This artifact includes both a code representation and a JSON equivalent of all compiler option descriptions (for non-Kotlin consumers). As well as metadata, such as the version in which each option was introduced or stabilized. ## Common options The following options are common for all Kotlin compilers. ### -api-version version Set the API version to control which Kotlin APIs your code can use at runtime. For example, if you use Kotlin compiler version 2.4.0 with `-api-version=2.1`, your code remains compatible with Kotlin standard library 2.1.0. You can't set the `-api-version` value higher than the `-language-version` value. In most cases, the API version and [language version](#language-version-version) should be the same. One exception is when you develop a library for consumers who must run an older version of the Kotlin standard library. In that case, set an older API version to avoid accidentally using APIs that aren't available to those consumers. For more information about how the API version affects compatibility, see [Backward compatibility guidelines for library authors](api-guidelines-backward-compatibility.html#choose-compatible-language-and-api-versions). ### -help (-h) Display usage information and exit. Only standard options are shown. To show advanced options, use `-X`. ### -kotlin-home path Specify a custom path to the Kotlin compiler used for the discovery of runtime libraries. ### -language-version version Set the language version to control which Kotlin language features are available during compilation. For example, if you want to benefit from new compilation performance improvements without changing compiler behavior, you can use a new compiler version with an older language version. With an older language version, you can't use newer language features, but you also don't see new errors and deprecations introduced after that version. This approach is especially useful for library authors who need to preserve compatibility with older Kotlin versions. For more information, see [Backward compatibility guidelines for library authors](api-guidelines-backward-compatibility.html#choose-compatible-language-and-api-versions). You can configure one of the latest three stable versions of Kotlin as the language version. For example, Kotlin 2.5.0 supports language versions as old as 2.2. If you use an older language version, you also need to use an older API version. For more information, see [-api-version version](#api-version-version). Tip: Technically, you can configure a newer language version to try upcoming language features before they are stabilized. However, it's best to enable individual features by following their dedicated instructions. ### -opt-in annotation Enable usages of API that [requires opt-in](opt-in-requirements.html) with a requirement annotation with the given fully qualified name. ### -P plugin:pluginId:optionName=value Pass an option to a Kotlin compiler plugin. Core plugins and their options are listed in the [Core compiler plugins](components-stability.html#core-compiler-plugins) section of the documentation. ### -progressive Enable the [progressive mode](whatsnew13.html#progressive-mode) for the compiler. In the progressive mode, deprecations and bug fixes for unstable code take effect immediately, instead of going through a graceful migration cycle. Code written in the progressive mode is backwards compatible; however, code written in a non-progressive mode may cause compilation errors in the progressive mode. ### -script Evaluate a Kotlin script file. When called with this option, the compiler executes the first Kotlin script (`*.kts`) file among the given arguments. ### -verbose Enable verbose logging output which includes details of the compilation process. ### -version Display the compiler version. ### -X Display information about the advanced options and exit. These options are currently unstable: their names and behavior may be changed without notice. ### Kotlin contract options The following options enable experimental Kotlin contract features. #### -Xallow-contracts-on-more-functions Enables contracts in additional declarations, including property accessors, specific operator functions, and type assertions on generic types. #### -Xallow-condition-implies-returns-contracts Allows using the `returnsNotNull()` function in contracts to assume a non-null return value for specified conditions. #### -Xallow-holdsin-contract Allows using the `holdsIn` keyword in contracts to assume that a boolean condition is `true` inside a lambda. #### -Xallow-returns-result-of Allows using the `returnsResultOf()` contract so that the unused return value checker can distinguish between results that can be ignored and meaningful results from higher-order functions. ### -Xallow-reified-type-in-catch Enables support for reified `Throwable` type parameters in `catch` clauses of `inline` functions. ### -Xcollection-literals Enables support for [collection literals](whatsnew24.html#support-for-collection-literals) with brackets syntax `[]`. ### -Xcompiler-plugin-order={plugin.before>plugin.after} Configure the running order of compiler plugins. The compiler runs `plugin.before` first, and then `plugin.after`: You can define multiple ordering rules for three or more plugins. For example: ```BASH kotlinc -Xcompiler-plugin-order=plugin.first>plugin.middle kotlinc -Xcompiler-plugin-order=plugin.middle>plugin.last ``` This results in the following running order: 1. `plugin.first` 2. `plugin.middle` 3. `plugin.last` If a compiler plugin isn't present, the corresponding rule is ignored. You can configure the following plugins by their IDs: | Compiler plugin |Plugin ID | ------------------------------ | `all-open`, `kotlin-spring` |`org.jetbrains.kotlin.allopen` | | AtomicFU |`org.jetbrains.kotlinx.atomicfu` | | Compose |`androidx.compose.compiler.plugins.kotlin` | | `js-plain-objects` |`org.jetbrains.kotlinx.jspo` | | `jvm-abi-gen` |`org.jetbrains.kotlin.jvm.abi` | | kapt |`org.jetbrains.kotlin.kapt3` | | Lombok |`org.jetbrains.kotlin.lombok` | | `no-arg`, `kotlin-jpa` |`org.jetbrains.kotlin.noarg` | | Parcelize |`org.jetbrains.kotlin.parcelize` | | Power-assert |`org.jetbrains.kotlin.powerassert` | | SAM with receiver |`org.jetbrains.kotlin.samWithReceiver` | | Serialization |`org.jetbrains.kotlinx.serialization` | This running order controls only the backend of compiler plugins and not the frontend. ### -Xdata-flow-based-exhaustiveness Enables data-flow–based exhaustiveness checks for `when` expressions. ### -Xexplicit-context-arguments Enables explicit [context arguments](context-parameters.html#pass-context-arguments-explicitly) for context parameters. This lets you resolve overload ambiguity by passing context arguments at the call site. ### -Xklib-ir-inliner Configure whether [intra-module inlining](whatsnew24.html#consistent-intra-module-function-inlining-during-klib-compilation) is enabled for Kotlin/Native, Kotlin/JS, and Kotlin/Wasm. By default, it's enabled. The option supports the following modes: * `disabled`: disables intra-module inlining for Kotlin/Native, Kotlin/JS, and Kotlin/Wasm. * `full`: enables cross-module inlining. ### -Xintrinsic-const-evaluation Enables [improved compile-time constants](whatsnew24.html#improved-compile-time-constants). ### -Xname-based-destructuring Configure how the compiler interprets [destructuring declarations](destructuring-declarations.html#name-based-destructuring) based on property names. The option supports the following modes: * `only-syntax`: enables the explicit form of name-based destructuring without changing the behavior of existing destructuring declarations. * `name-mismatch`: reports warnings when position-based destructuring in data classes uses variable names that don't match the property names. * `complete`: enables short-form name-based destructuring with parentheses and continues supporting position-based destructuring with square bracket syntax. ### -Xphases-to-dump-before Set to `ExternalPackageParentPatcherLowering` to create a dump file after the IR lowering compilation stage. Configure the output directory for the Kotlin/JVM with the [-Xdump-directory](#xdump-directory) compiler option. ### -Xrepl Activates the Kotlin REPL. ```BASH kotlinc -Xrepl ``` ### -Xreturn-value-checker Configure how the compiler [reports ignored results](unused-return-value-checker.html): * `disable`: disables the unused return value checker (default). * `check`: enables the checker and reports warnings for ignored results from marked functions. * `full`: enables the checker, treats all functions in your project as marked, and reports warnings for ignored results. ### Warning management #### -nowarn Suppress all warnings during compilation. #### -Werror Treat all warnings as compilation errors. #### -Wextra Enable [additional declaration, expression, and type compiler checks](whatsnew21.html#extra-compiler-checks) that emit warnings if true. #### -Xrender-internal-diagnostic-names Prints internal diagnostic names alongside warnings. This is useful for identifying the `DIAGNOSTIC_NAME` configured for the `-Xwarning-level` option. #### -Xwarning-level Configure the severity level of specific compiler warnings: ```BASH kotlinc -Xwarning-level=DIAGNOSTIC_NAME:(error|warning|disabled) ``` * `error`: raises only the specified warning to an error. * `warning`: emits a warning for the specified diagnostic and is enabled by default. * `disabled`: suppresses only the specified warning module-wide. You can adjust warning reporting in your project by combining module-wide rules with specific ones: | Command |Description | ------------------------ | `-nowarn -Xwarning-level=DIAGNOSTIC_NAME:warning` |Suppress all warnings except for the specified ones. | | `-Werror -Xwarning-level=DIAGNOSTIC_NAME:warning` |Raise all warnings to errors except for the specified ones. | | `-Wextra -Xwarning-level=DIAGNOSTIC_NAME:disabled` |Enable all additional checks except for the specified ones. | If you have many warnings to exclude from the general rules, you can list them in a separate file using [@argfile](#argfile). You can use [-Xrender-internal-diagnostic-names](#xrender-internal-diagnostic-names) to discover the `DIAGNOSTIC_NAME`. ### @argfile Read the compiler options from the given file. Such a file can contain compiler options with values and paths to the source files. Options and paths should be separated by whitespaces. For example: ``` -include-runtime -d hello.jar hello.kt ``` To pass values that contain whitespaces, surround them with single (') or double (") quotes. If a value contains quotation marks in it, escape them with a backslash (\). ``` -include-runtime -d 'My folder' ``` You can also pass multiple argument files, for example, to separate compiler options from source files. ```BASH $ kotlinc @compiler.options @classes ``` If the files reside in locations different from the current directory, use relative paths. ```BASH $ kotlinc @options/compiler.options hello.kt ``` ## Kotlin/JVM compiler options The Kotlin compiler for JVM compiles Kotlin source files into Java class files. The command-line tools for Kotlin to JVM compilation are `kotlinc` and `kotlinc-jvm`. You can also use them for executing Kotlin script files. In addition to the [common options](#common-options), Kotlin/JVM compiler has the options listed below. ### -classpath path (-cp path) Search for class files in the specified paths. Separate elements of the classpath with system path separators (; on Windows, : on macOS/Linux). The classpath can contain file and directory paths, ZIP, or JAR files. ### -d path Place the generated class files into the specified location. The location can be a directory, a ZIP, or a JAR file. ### -include-runtime Include the Kotlin runtime into the resulting JAR file. Makes the resulting archive runnable on any Java-enabled environment. ### -jdk-home path Use a custom JDK home directory to include into the classpath if it differs from the default `JAVA_HOME`. ### -Xjdk-release=version Specify the target version of the generated JVM bytecode. Limit the API of the JDK in the classpath to the specified Java version. Automatically sets [-jvm-target version](#jvm-target-version). Possible values are `1.8`, `9`, `10`, ..., `26`. Note: This option is [not guaranteed](https://youtrack.jetbrains.com/issue/KT-29974) to be effective for each JDK distribution. ### -jvm-default mode Control how functions declared in interfaces are compiled to default methods on the JVM. | Mode |Description | --------------------- | `enable` |Generates default implementations in interfaces and includes bridge functions in subclasses and `DefaultImpls` classes. (Default) | | `no-compatibility` |Generates only default implementations in interfaces, skipping compatibility bridges and `DefaultImpls` classes. | | `disable` |Generates only compatibility bridges and `DefaultImpls` classes, skipping default methods. | ### -jvm-target version Specify the target version of the generated JVM bytecode. Possible values are `1.8`, `9`, `10`, ..., `26`. The default value is `1.8`. ### -java-parameters Generate metadata for Java 1.8 reflection on method parameters. ### -module-name name (JVM) Set a custom name for the generated `.kotlin_module` file. ### -no-jdk Don't automatically include the Java runtime into the classpath. ### -no-reflect Don't automatically include the Kotlin reflection (`kotlin-reflect.jar`) into the classpath. ### -no-stdlib (JVM) Don't automatically include the Kotlin/JVM stdlib (`kotlin-stdlib.jar`) and Kotlin reflection (`kotlin-reflect.jar`) into the classpath. ### -script-templates classnames[,] Script definition template classes. Use fully qualified class names and separate them with commas (,). ### -Xadd-modules=module[,] Specify the root modules to resolve in addition to the initial modules. Set the `ALL-MODULE-PATH` value to resolve all modules on the module path. Separate multiple modules with commas (,). For example, to resolve the incubator module: ```BASH kotlinc -Xadd-modules=jdk.incubator.vector ``` ### -Xdump-directory Configure the dump file directory for the [-Xphases-to-dump-before](#xphases-to-dump-before) compiler option. ### -Xjvm-expose-boxed Generate boxed versions of all inline value classes in the module, along with boxed variants of functions that use them, making both accessible from Java. For more information, see [Inline value classes](java-to-kotlin-interop.html#inline-value-classes) in the guide to calling Kotlin from Java. ### -Xnullability-annotations Configure how the Kotlin compiler interprets nullability annotations from specific Java packages. For the full list of supported annotations and configuration options, see [Nullability annotations](java-interop.html#nullability-annotations). ## Kotlin/JS compiler options The Kotlin compiler for JS compiles Kotlin source files into JavaScript code. The command-line tool for Kotlin to JS compilation is `kotlinc-js`. In addition to the [common options](#common-options), Kotlin/JS compiler has the options listed below. ### -libraries path Paths to Kotlin libraries with `.meta.js` and `.kjsm` files, separated by the system path separator. ### -main {call|noCall} Define whether the `main` function should be called upon execution. ### -meta-info Generate `.meta.js` and `.kjsm` files with metadata. Use this option when creating a JS library. ### -module-kind {umd|commonjs|amd|plain} The kind of JS module generated by the compiler: * `umd` - a [Universal Module Definition](https://github.com/umdjs/umd) module * `commonjs` - a [CommonJS](http://www.commonjs.org/) module * `amd` - an [Asynchronous Module Definition](https://en.wikipedia.org/wiki/Asynchronous_module_definition) module * `plain` - a plain JS module To learn more about the different kinds of JS modules and the distinctions between them, see [this](https://www.davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd/) article. ### -no-stdlib (JS) Don't automatically include the default Kotlin/JS stdlib into the compilation dependencies. ### -output filepath Set the destination file for the compilation result. The value must be a path to a `.js` file including its name. ### -output-postfix filepath Add the content of the specified file to the end of the output file. ### -output-prefix filepath Add the content of the specified file to the beginning of the output file. ### -source-map Generate the source map. ### -source-map-base-dirs path Use the specified paths as base directories. Base directories are used for calculating relative paths in the source map. ### -source-map-embed-sources {always|never|inlining} Embed source files into the source map. ### -source-map-names-policy {simple-names|fully-qualified-names|no} Add variable and function names that you declared in Kotlin code into the source map. | Setting |Description |Example output | ---------------------------------------- | `simple-names` |Variable names and simple function names are added. (Default) |`main` | | `fully-qualified-names` |Variable names and fully qualified function names are added. |`com.example.kjs.playground.main` | | `no` |No variable or function names are added. |N/A | ### -source-map-prefix Add the specified prefix to paths in the source map. ### -target {es5|es2015|es2020} Generate JS files for the specified ECMA version. ### -Xenable-implementing-interfaces-from-typescript Allow [implementing Kotlin interfaces](whatsnew2320.html#implementing-kotlin-interfaces-from-javascript-typescript) exported with the `@JsExport` annotation from JavaScript/TypeScript. ### -Xes-long-as-bigint Enable support for the JavaScript `BigInt` type to represent Kotlin `Long` values when compiling to modern JavaScript (ES2020). This option is required for the `es5` and `es2015` targets only. The `es2020` target enables this option by default. ### -Xsuspend-lambda-exporting Allow [exporting suspending lambda expressions](js-to-kotlin-interop.html#export-suspending-lambdas) declared in `@JsExport` declarations as JavaScript `async` functions. ## Kotlin/Native compiler options Kotlin/Native compiler compiles Kotlin source files into native binaries for the [supported platforms](native-overview.html#target-platforms). The command-line tool for Kotlin/Native compilation is `kotlinc-native`. In addition to the [common options](#common-options), Kotlin/Native compiler has the options listed below. ### -enable-assertions (-ea) Enable runtime assertions in the generated code. ### -entry name (-e name) Specify the qualified entry point name. ### -g Enable emitting debug information. This option lowers the optimization level and should not be combined with the [-opt](#opt) option. ### -generate-test-runner (-tr) Produce an application for running unit tests from the project. ### -generate-no-exit-test-runner (-trn) Produce an application for running unit tests without an explicit process exit. ### -include-binary path (-ib path) Pack external binary within the generated klib file. ### -library path (-l path) Link with the library. To learn about using libraries in Kotlin/native projects, see [Kotlin/Native libraries](native-libraries.html). ### -library-version version (-lv version) Set the library version. ### -linker-option Pass an argument to the linker during binary building. This can be used for linking against some native library. ### -linker-options args Pass multiple arguments to the linker during binary building. Separate arguments with whitespaces. ### -list-targets List the available hardware targets. ### -manifest path Provide a manifest addend file. ### -module-name name (Native) Specify a name for the compilation module. This option can also be used to specify a name prefix for the declarations exported to Objective-C: [How do I specify a custom Objective-C prefix/name for my Kotlin framework?](native-faq.html#how-do-i-specify-a-custom-objective-c-prefix-name-for-my-kotlin-framework) ### -native-library path (-nl path) Include the native bitcode library. ### -no-default-libs Disable linking user code with the prebuilt [platform libraries](native-platform-libs.html) distributed with the compiler. ### -nomain Assume the `main` entry point to be provided by external libraries. ### -nopack Don't pack the library into a klib file. ### -nostdlib Don't link with stdlib. ### -opt Enable compilation optimizations and produce a binary with better runtime performance. It's not recommended to combine it with the [-g](#g) option, which lowers the optimization level. ### -output name (-o name) Set the name for the output file. ### -produce output (-p output) Specify output file kind: * `program` * `static` * `dynamic` * `framework` * `library` * `bitcode` ### -repo path (-r path) Library search path. For more information, see [Library search sequence](native-libraries.html#library-search-sequence). ### -target target Set the hardware target. To see the list of available targets, use the [-list-targets](#list-targets) option. ### -Xccall-mode Enable the [new interoperability mode](whatsnew2320.html#new-interoperability-mode-for-c-or-objective-c-libraries) for C or Objective-C libraries imported via cinterop. ### -Xoverride-konan-properties=min.version.* Configure lower supported versions of Apple targets than the Kotlin defaults. For example: ```BASH kotlinc -Xoverride-konan-properties=minVersion.ios=14.0 kotlinc -Xoverride-konan-properties=minVersion.macos=11.0 kotlinc -Xoverride-konan-properties=minVersion.tvos=14.0 kotlinc -Xoverride-konan-properties=minVersion.watchos=7.0 ```