如何使用 Gradle 将编译器参数传递给 Kotlin 编译器 [英] How to pass compiler arguments to Kotlin Compiler with Gradle

查看:41
本文介绍了如何使用 Gradle 将编译器参数传递给 Kotlin 编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Kotlin gradle 插件用 Gradle 编译 Kotlin 库 jar:

I'm compiling a Kotlin library jar with Gradle using the Kotlin gradle plugin:

应用插件:'kotlin'

我试图找到一种方法将一个简单的 -include-runtime 编译器参数传递给 kotlin 编译器.我似乎根本找不到任何关于此的文档.我尝试模仿 java 插件,但这似乎不起作用.这里是一些关于使用命令行编译器的文档,但 gradle 文档没有不要提及传递编译器参数的任何内容.

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.

推荐答案

您可以在 KotlinCompile 类型的任务的 kotlinOptions 闭包中指定编译器参数.对于所有这些,例如:

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 文档:使用 Gradle

这篇关于如何使用 Gradle 将编译器参数传递给 Kotlin 编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆