How to pass compiler arguments to Kotlin Compiler with Gradle

后端 未结 3 1230
暖寄归人
暖寄归人 2020-12-06 09:29

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 sim

相关标签:
3条回答
  • 2020-12-06 09:57

    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

    0 讨论(0)
  • 2020-12-06 09:59

    If anyone is using the kotlin DSL you can try this too:

    import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
    
    val compileKotlin: KotlinCompile by tasks
    compileKotlin.kotlinOptions.includeRuntime = true
    
    0 讨论(0)
  • 2020-12-06 10:22

    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

    0 讨论(0)
提交回复
热议问题