I'm compiling a Kotlin library jar with Gradle using the Kotlin gradle plugin:
apply plugin: 'kotlin'
I'm trying to find a way to pass a simple -include-runtime
compiler arguments to the kotlin compiler. I can't seem to find any documentation on this at all. I tried mimicking the java plugin, but that didn't seem to work. Here is some documentation about working with the command line compiler, but the gradle documentation doesn't mention anything about passing compiler arguments.
Gradle is a build system that is very commonly used in the Java, Android, and other ecosystems. It is the default choice for Kotlin/Native and Multiplatform when it comes to build systems.
Go to Intellij Preferences -> Build, Execution, Deployment -> Kotlin Compiler. Update Language version and Api version to the one you wish. This should be the accepted answer.
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 order to build a Kotlin project with Gradle, you should apply the Kotlin Gradle plugin to your project and configure the dependencies. Apply the Kotlin Gradle plugin by using the Gradle plugins DSL.
Pass an option to a Kotlin compiler plugin. Available plugins and their options are listed in the Tools > Compiler plugins section of the documentation. Provide source compatibility with the specified version of Kotlin. Allow using declarations only from the specified version of Kotlin bundled libraries.
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" The following options are common for all Kotlin compilers. Display the compiler version.
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 kotlinOptions property of the Kotlin compilation task. For details, see Gradle.
You can specify compiler args inside kotlinOptions
closure on tasks of KotlinCompile
type. For all of them, for instance:
allprojects {
...
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = '1.6'
freeCompilerArgs += '-include-runtime'
}
}
}
Kotlin docs: using Gradle
Try this:
compileKotlin {
kotlinOptions.includeRuntime = true
}
UPD btw this exact option includeRuntime
couldn't work because it is not Gradle way. There are many options to build jar with dependencies in Gradle: Gradle – Create a Jar file with dependencies, Gradle Shadow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With