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.
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.
因为AppEngine执行编译.类文件,它不关心JVM语言生成了这些文件.这意味着我们可以使用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
.