Gradle configuration
suggest changekotlin-gradle-plugin compiles Kotlin code with Gradle. Its version should match the Kotlin version you want to use. For example, to use Kotlin 1.0.3, apply kotlin-gradle-plugin version 1.0.3 as well.
It’s a good idea to externalize this version in gradle.properties or in ExtraPropertiesExtension:
buildscript {
ext.kotlin_version = '1.0.3'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Then you need to apply this plugin to your project. The way you do this differs when targeting different platforms:
Targeting JVM
apply plugin: 'kotlin'
Targeting Android
apply plugin: 'kotlin-android'
Targeting JS
apply plugin: 'kotlin2js'
These are the default paths:
- kotlin sources:
src/main/kotlin - java sources:
src/main/java - kotlin tests:
src/test/kotlin - java tests:
src/test/java - runtime resources:
src/main/resources - test resources:
src/test/resources
You may need to configure SourceSets if you’re using custom project layout.
Finally, you’ll need to add Kotlin standard library dependency to your project:
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
If you want to use Kotlin reflection, also add compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version".
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents