How to pass compiler arguments to Kotlin Compiler

2019-01-20 07:50发布

问题:

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.

回答1:

A way to pass arbitrary compiler options:

kotlinOptions {
    freeCompilerArgs = ['-include-runtime']
}


回答2:

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



标签: gradle kotlin