Like the title says, how can I use Kotlin when developing AppEngine projects? I'm using IntelliJ/Android Studio with Gradle as my build tool.
Since AppEngine executes compiled .class files, it doesn't care what JVM language produced these. This means we can use Kotlin.
One way to do this is by using Gradle and the Gradle App Engine plugin. Create a project with a build.gradle
that looks something like this. Then add the Kotlin dependencies and apply the plugin. The final build file looks something like this:
buildscript {
ext.kotlin_version = '1.0.6' //replace with latest Kotlin version
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.32' //Replace with latest GAE plugin version
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral();
}
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.32' //Replace with latest GAE SDK version
compile 'javax.servlet:servlet-api:2.5'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
}
Since M11 you don't need to have a separate directory for Kotlin files so you can just add your .kt files to src/main/java
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With