Using standalone jars with android studio app engine + gradle - google-app-engine

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'])

Related

app-gradle-plugin breaks tasks in multi project build

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.

Porting Angular app with Cordova also using Bower

I've installed the iOS and Android build tools for Cordova and after I have run cordova build in my main directory I get an empty www folder. My Angular source is normally managed by bower, should I manually copy them into the source directory for the new build?
Cordova Documentation for Cordova Build Command
The cordova prepare step (which should run when you use cordova build), copies files from your project-wide www/ folder, and then compiles the project. When I use grunt or gulp with my ionic/cordova project, I build my javascript/html project into the main www/ folder before running cordova build, which would include copying/concatenating bower dependencies.

How to use Kotlin in AppEngine projects using Gradle

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.

Failed to import App engine DatastoreService using Android Studio Beta (0.8.1)

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'}

How to convert maven project to web application project?

I want to convert a maven project to a web application project, which should contain web.xml. I am using eclipse juno 4.2 with m2e (maven integration for eclipse) plugin software.
Any reply would be appreciated.
Install m2e-wtp
In your pom.xml, change or add the war packaging
right-click on project > Maven > Update project
m2e-wtp will create the src/main/webapp folder and add the Dynamic Web project Facet¤
manually add a WEB-INF folder under src/main/webapp
right-click on project > Java EE Tools > Generate Deployment Descriptor stub
It will create a web.xml under src/main/webapp/WEB-INF/
¤ By default, the web facet is set to 2.5. You should update it, if needed, under project properties > Project Facets BEFORE generating the web.xml
I assume your current project is a maven project which produces jar. Please confirm.
I have not come across any utility which can convert a jar project to a war project.
You have following two options -
Simple open the pom.xml and change jar to war. Create folder webapp under src/main and create a web.xml
Create a new web app project via maven command line choosing webapp archetype or via eclipse choosing maven webapp achetype. Define dependency to your jar project.
If you can provide more information based on my suggestion then probably I can help.

Resources