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.
Related
I want to use the frontend-gradle-plugin with the app-gradle-plugin for AppEngine.
If I start with the "multi-project-war-application example everything builds fine.
When I add the app-gradle-plugin using either the method in the documentation linked above the build the fails. For example if I add it through a build script block:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.4.1'
}
}
apply plugin: 'com.google.cloud.tools.appengine'
Gradle will fail with:
A problem occurred configuring project ':backend'.
> Could not create task ':backend:processFrontendResources'.
> Task with name 'assembleFrontend' not found in project ':frontend'.
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':backend'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
...
Note that in the example project the build.gradle has the following part:
tasks.register('processFrontendResources', Copy) {
// Directory containing the artifacts in the frontend project
def frontendBuildDir = file("${project(':frontend').buildDir}/www")
// Directory where the frontend artifacts must be copied to be packaged alltogether with the backend by the 'war'
// plugin.
def frontendResourcesDir = file("${project.buildDir}/resources/main/public")
group 'Frontend'
description 'Process frontend resources'
dependsOn project(':frontend').tasks.named('assembleFrontend')
from frontendBuildDir
into frontendResourcesDir
}
After adding the app-gradle-plugin the dependsOn line fails. Through debugging I've found that project(':frontend').tasks becomes empty after the app-gradle-plugin is added.
What is the app-gradle-plugin doing that is changing tasks in the project? Is there a different way I can look up the assembleFrontend task that will work with the app-gradle-plugin or is the plugin fundamenatally incompatible with multi project gradle builds?
I have cloned the repo frontend-gradle-plugin and added the app engine gradle plugin to the build.gradle file of the example multi-project-war-application. Here is the content of it:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:2.4.1'
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'com.google.cloud.tools.appengine'
That is all I have and I was able to run ./gradlew bootRun, ./gradlew tasks & ./gradlew build without any issues.
I have taken as a reference the build.gradle file from the app engine standard quickstart.
I hope you find this useful.
I opened an issue with the project on Github. They have a new ticket they opened to track the fix but it will be in development for a while. In the mean time the workaround recommendation is to:
not use a "managed Cloud SDK." ("Managed" means app-gradle-plugin automatically downloads an SDK at some cache location (e.g., ~/.cache/google-cloud-tools-java/...) and keeps updating it transparently.) So, a workaround is to manually download the SDK and periodically update it yourself. For example, download the Cloud SDK, unzip it into your home directory (probably you'll also need to do gcloud components install app-engine-java after unzipping), and configure app-gradle-plugin to use the downloaded Cloud SDK:
The Groovy DSL example they gave:
appengine {
tools.cloudSdkHome = '/home/chanseok/google-cloud-sdk'
}
The Kotlin DSL I am using successfully:
the<AppEngineStandardExtension>().apply {
appengine {
tools {
setCloudSdkHome(File("/home/ciferkey/google-cloud-sdk"))
}
}
}
I am able to use dependsOn with that configuration change. Once the ticket above is finished and release this should be unnecessary.
Since it's not a maven project, how to build https://github.com/snowflakedb/spark-snowflake?
There is a Maven repository here:
https://search.maven.org/classic/#search%7Cga%7C1%7Cg%3A%22net.snowflake%22
There is also full documentation support here:
https://docs.snowflake.com/en/user-guide/spark-connector-install.html
Library camel-swagger-java expose swagger during runtime generated based on RestConfigurationDefinition.
Is it possible to generate a swagger file during a maven build?
The only possibility I've already found is to generate a swagger during JUnit test execution, when Spring context is running, which is clumsy.
Finally, I made a simple maven plugin which can be used for swagger generation during maven build. https://github.com/PavelKa/apache-camel-swagger-plugin
I have an app engine project created via the wizard in android studio. The generated build.gradle file looks like this:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
dependencies {
compile fileTree(dir: 'main/webapp/WEB-INF/lib', include: ['*.jar'])
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
...
I have put a standalone jar in the WEB-INF/lib folder. I rebuild / refresh gradle, but android studio can't seem to see the classes in the jar file.
Is there something else we need to add to the dependencies closure to make the jar classes accessible?
Thanks
You probably need to add src to your path
compile fileTree(dir: 'src/main/webapp/WEB-INF/lib', include: ['*.jar'])
import com.google.appengine.api.datastore.DatastoreService;
I migrated my App Engine Java servlet module from Eclipse Kepler to Android Studio using the Export to -> build.gradle from Eclipse.
The problem is that Android Studio doesnt recognize the imports mentioned above.
I already did the following:
-Updated the corresponding build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.6'
}
}
(...)
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.6'
compile 'javax.servlet:servlet-api:2.5' }
I downloaded the Android Support repository from the SDK
I also tried to find the jars needed from the download jar from web, option, after clicking on the Datastoreservice Datastore =...
The module I created in Android Studio is the proper module for a Java Http Servlet.
Any ideas, how to import the appengine datastore service using build.gradle or by any other method?
Thank you
Found it!
Just added the following to my build.gradle file and the imports were successful. Although the app-engine endpoints seem irrelevant, the com.google.appengine.api.datastore.DatastoreService; was imported
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.1'
compile 'com.google.appengine:appengine-endpoints:1.9.1'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.1'
compile 'javax.servlet:servlet-api:2.5'}