Gradle

In your Gradle project, you have the build.gradle file located somewhere in the root of your project. Make sure that you have this buildScript section in that file.

buildscript {
ext.kotlin_version = '1.2.40'

repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

This tells Gradle to use a Kotlin plugin and adds Maven central to the list of repositories. With the plugin added, we still need the Kotlin standard library to be able to compile a Kotlin source code. If you have multiple Gradle modules, make sure that the module's build.gradle file in which you plan to use Kotlin has the following:

apply plugin: "kotlin"

repositories {
mavenCentral()
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}

If you don't have multiple build.gradle files, then put this to the root build.gradle file. The same one in which you added the Kotlin plugin.

You can also set various compiler options under the compile Kotlin section. For example, with the kotlinOptions.jvmTarget = "1.8" option we told the Kotlin compiler to produce Java 1.8 compatible bytecode.

Now, if you sync your Gradle project, you should be able to add Kotlin files to it and compile them with Gradle.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.26.217